Integration with Google Calendar?

Posted on
  • Dear all,

    I just realized that I would love to make an Espruino project aimed at printing on a display my daily agenda. I have not yet thought about how I would implement it, but my first question is related to how to get the calendar content from Google. Does anyone ever tried to implement an integration with the Google Calendar API?

    Thanks for your feedback.
    Have a nice day.

  • Not me, but you might look first at IFTTT. There could be something you could set up there which would take care of the heavy lifting, so you can focus on just the call/data.

  • I hate to be one of those... But unless it's a excersize, this solution could be more easily done with a simply raspberry pi (and old one you have lying around somewhere) and the old monitor you think is too small for your computer:

    https://www.instructables.com/id/Raspber­ry-Pi-Wall-Mounted-Google-Calendar/

    Should you insist. I'd suggest having your own API endpoint that your espruino hits and you do all the heavy lifting on a serverless/azure functions/lambda solution hosted somewhere for free:

    https://developers.google.com/calendar/v­3/reference/calendarList/get#examples

  • Thanks @Ollie and @DamianMontero for your answers, I appreciate!

    Do you think I could use a Google Apps Script function to get the daily calendar (as shown here https://www.youtube.com/watch?v=sm1-l5-z­3ag

    ) and then call the script from Espruino?

    I tried this:

    var WIFI_NAME = "WIFI_NAME";
    var WIFI_OPTIONS = { password : "WIFI_PASSWORD" };
    var GsToken='YOUR GOOGLE APPS SCRIPT TOKEN HERE';
    
    var wifi;
    
    function getCalendar()
    {
      var options = {
        host: 'https://script.google.com',
        port: '443',
        path:'/macros/s/'+GsToken+'/exec',
        protocol: "https:",
        method:'GET',
        headers: {
          "Content-Type":"application/x-www-form-u­rlencoded"
        }
      };
    
      console.log("Connecting to Google");
      require("http").request(options, function(res)  {
        console.log("Connected to Google");
        var nRecv = 0;
        res.on('data', function(data) { nRecv += data.length; });
        res.on('close', function(data) {
          console.log("Google connection closed, "+nRecv+" bytes received");
          setTimeout(getCalendar, 10000); // once every 10 seconds
        });
      }).end();
    }
    
    function onConnected(err) {
      if (err) throw err;
      wifi.getIP(function(e,ip) {
        console.log(ip);
        getCalendar();
      });
    }
    
    var Inited=false;
    function Init()
    {
      if(!Inited)
      {
        Inited=true;
        wifi = require("Wifi");
        wifi.connect(WIFI_NAME, WIFI_OPTIONS, onConnected);
      }
    }
    function onInit() {
      setTimeout("Init();",1000);
    }
    
    Init();
    

    The console output is

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v04 (c) 2019 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 512KB:256/256, manuf 0xef chip 0x4015
    >
    {
      "ip": "192.168.43.173",
      "netmask": "255.255.255.0",
      "gw": "192.168.43.1",
      "mac": "18:fe:34:f5:6a:a9"
     }
    Connecting to Google
    >
    

    Then nothing happens. I think I am pretty close to have a solution not based on a third party service, but, well, it doesn't work as is... I don't know if ESP8266 can do https requests directly or if I need to use some kind of HTTPSRedirect library, used on the Arduino world...
    If anyone has any hints to help me go a step further, that would be awesome :-)

  • ESP8266 has no libs build in to run https, only http is available.

    A HTTP2HTTPS redirection is needed.

    Edit: http://forum.espruino.com/comments/13706­109/

  • It seems that HTTP2HTTPS does not work. I couldn't figure out exactly why. However, many people in Arduino world is using the HTTPSRedirect library to call a Google Apps Script ( https://github.com/electronicsguy/ESP826­6/tree/master/HTTPSRedirect)

    Unfortunately this mechanisms is running on the embedded side and is not compatible with Espruino. I searched for similar mechanism in Espruino but did not find anything. Just to be sure, I am asking here: Does anyone ever implemented such a redirection mechanism?

    Thanks for any help :-)

  • I think that library still makes an HTTPS request? It just follows redirects to find the right URL first, even if that URL is HTTPS?

    Basically I think you'd be better with an Espruino WiFi or ESP32 which supports HTTPS - if there's a redirect involved it's pretty trivial to get that working with Espruino, but HTTPS on ESP8266 isn't really an option right now.

    While HTTP2HTTPS might work to make an HTTPS request, the Google stuff may do a bunch of authentication which could make it hard for HTTP2HTTPS. It may even be a bit tricky to do on an Espruino with HTTPS - I'm not sure.

    If you came up with a simple script (which did just listed something non-private) then I could try it here and see if it worked?

  • Thr 2019.10.17

    I'm with @DamianMontero post #3 on this one. Although a bit of additional code to write and deploy, IMHO it will be far easier to tap in to the myriad of examples, using Python, PHP or my choice Go to access the Calendar app with a web service created using Google AppEngine for instance, and return a well formed data payload in Json format to a simple http request from the Espruino device. Allows for the authentication using their proven examples and also allows to create a user defined payload stripping out the unnecessary. My 0.02 worth

  • As weekend is approaching, you might fancy going down the rabbit hole :)

    Have a look at Cloudflare workers, you need a domain on their nameservers, but then you can configure a route - http allowed - and set up a worker (function) that responds on that route, and proxying requests can be done in the worker.

    Really, just a foward proxy as suggested above, when all said and done, but quite interesting.

    I had a look at IFTTT again (first time in a while) does not seem as flexible as it was, and the hooks piece now seems to default to https too, so not an option.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Integration with Google Calendar?

Posted by Avatar for Jean-Philippe_Rey @Jean-Philippe_Rey

Actions