• Kind of a "quick" project to get comfortable with the ESP32.

    It connects to the wunderground API, and pulls the latest forecast string, and displays across SSD1306 (I also wrote a version with the HD44780 I2C).

    See the code here:
    https://github.com/wga22/esp8266/blob/ma­ster/espurino/ESP32_drawforecast.js

    Interesting part of the code is the parsing of the JSON from wunderground. Not my best code, just slopping something together to see how it works. Love the ESP32, has right level of performance for doing real level of work. Hoping ESPRUINO team continues to get it love! A special thanks to the brilliance of the "loadModule" versatility!

    function drawForecast()
    {
        //getting weather now, so allow another process to get weather
        setTime.val = "";
        var ZIP= '22182';
        HTTP.get((SURLAPI + ZIP + ".json"), function(res) 
        {
            res.on('data', function(wunderString) {   drawForecast.val += wunderString;   });
            res.on('close', function(fLoaded) 
            {
                console.log("Connection to wunder closed");
                drawForecast.obj = JSON.parse( drawForecast.val );
                drawForecast.val = "";
                writeStringToLCD(drawForecast.obj.foreca­st.txt_forecast.forecastday[0].fcttext);­
            });
            res.on('error', function(e){console.log("error getting wunderground details");});   //TODO: test, and handle by saving values?
        });
    }
    drawForecast.val = "";
    drawForecast.obj = null;
    

    1 Attachment

    • IMG_20180318_145436.jpg
  • Hi,

    Thanks for posting. Interesting to see that you are loading the module dynamically:
    https://github.com/wga22/esp8266/blob/ma­ster/espurino/ESP32_drawforecast.js#L64

    Why are you doing that?

    A line or two between the text rows might be a bit more readable!

  • @Wilberforce good tip on the line between text. That code has room for improvement in that I might like to use regex to split the text in a more natural place.

    I do load the module dynamically, because I thought I had to. Perhaps you're suggesting I only need to do that prior to the save?

  • @Will
    I guess you are not using the web IDE then - this pulls in the required modules and uploads with your code on send, so you don't need to explicitly load the module.

  • Oh, I am using the webIDE (love it), I didn't realize it would do that for me. Very cool.

  • As you already have
    graphics = require("SSD1306").connect(I2C1, initGraphics, { height : 64 });

    You can get rid of your oninit() that calls load module.

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

Wunderground weather forecast to a LCD HD44780 and SSD1306

Posted by Avatar for Will @Will

Actions