Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Japio
    3. Best
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Best posts made by Japio

    • ESP8266 gateway + WebServer = Awesome!

      Hi,

      I used the indications feature of MySensors 2.0 and a webserver to have the gateway provide status information through a web page:

      0_1474090614863_Gateway.JPG

      This is how I did it:

      In the global section I added this:

      #include <ESP8266WiFi.h>
      #include <ESP8266WebServer.h>
      #include <WiFiClient.h>
      
      ESP8266WebServer WebServer(80);
      unsigned long startTime=millis();
      unsigned long gwMsgSent = 0;
      unsigned long gwMsgRec = 0;
      
      String WebPage = "<h1>ESP8266 MQTT client for Mysensors</h1>";
      
      void setupWebServer();
      void showRootPage();
      String readableTimestamp(unsigned long milliseconds);
      

      In the setup() Added this:

        Serial.begin(9600);
      
        setupWebServer();
      

      Defined the following functions:

      void setupWebServer()
      {
        WebServer.on("/", HTTP_GET, showRootPage);
      
      
        WebServer.begin();
        Serial.println("WebServer started...");
      
      }
      
      void indication( const indication_t ind )
      {
        switch (ind)
        {
          case INDICATION_GW_TX:
            gwMsgSent++;
            break;
      
          case INDICATION_GW_RX:
            gwMsgRec++;
            break;
      
          default:
          break;
        };
      }
      
      void showRootPage()
      {
        unsigned long runningTime = millis() - startTime;
        String page = WebPage;
        page+="<br>General information</br>";
        page+= "<style> table, th, td { border: 1px solid black;}</style>";
        page+="<table style=\"width:400\">";
        page+="<tr>"; page+=  "<th>Item</th>";        page+=  "<th>Value</th>";                                            page+="</tr>";
        page+="<tr>"; page+=  "<td>Running for</td>";               page+=  "<td>"; page += readableTimestamp(runningTime) ; page+= "</td>";                 page+="</tr>";
        page+="<tr>"; page+=  "<td>Gateway messages sent</td>";     page+=  "<td>"; page += gwMsgSent; page+= "</td>";                                page+="</tr>";
        page+="</table>";
      
        page+="<br>MySensors gateway information</br>";
        page+= "<style> table, th, td { border: 1px solid black;}</style>";
        page+="<table style=\"width:400\">";
        page+="<tr>"; page+=  "<th>Item</th>";        page+=  "<th>Value</th>";                                            page+="</tr>";
        page+="<tr>"; page+=  "<td>Gateway messages received</td>";     page+=  "<td>"; page += gwMsgRec; page+= "</td>";                                page+="</tr>";
        page+="<tr>"; page+=  "<td>Gateway messages sent</td>";     page+=  "<td>"; page += gwMsgSent; page+= "</td>";                                page+="</tr>";
        page+="</table>";
      
        Serial.println("WS: Send root webpage");
        WebServer.send(200, "text/html", page);
      }
      
      String readableTimestamp(unsigned long milliseconds)
      {
        int days = milliseconds / 86400000;
      
        milliseconds=milliseconds % 86400000;
        int hours = milliseconds / 3600000;
        milliseconds = milliseconds %3600000;
      
         int minutes = milliseconds / 60000;
         milliseconds = milliseconds % 60000;
      
         int seconds = milliseconds / 1000;
         milliseconds = milliseconds % 1000;
      
          String timeStamp;
          timeStamp = days; timeStamp += " days, ";
          timeStamp += hours; timeStamp += ":";
          timeStamp += minutes ; timeStamp +=  ":";
          timeStamp +=seconds; timeStamp += ".";
          timeStamp +=milliseconds;
          Serial.println(timeStamp);
          return timeStamp;
      }
      

      And in loop() added the following:

        WebServer.handleClient();
      

      If you have any more idaes on what to add to this page (I am thinking about maintaining a list of registered nodes and sensors) just post a reply!

      posted in Development
      Japio
      Japio
    • RE: ESP8266 gateway + WebServer = Awesome!

      Yes, it actually is.

      Current features:

      • Stores wifi and mqtt broker configuration in flash. When no configuration is found, or the flash button of the ESP is pressed for 10 seconds, released, and then the reset button is pressed, it will restart in access point mode, allowing configuration to be done.
      • Status page shows all nodes and sensors connected and the last sensors data and presentation time.
      • Status indications on the box itself using a neopixel stick of 8 leds:
        • Gateway status (operation or access point mode)
        • Wifi strength
        • Mqtt connection status
        • Transmit error
        • Receive indication.

      I designed a board to nicely fit in a standard Aliexpress housing.

      Main problem still is the instability of the ESP, it resets often, and I tried to work around it by maikng sure it resets quickly.

      I am planning to make a more elaborate topic, including board designs soon.

      posted in Development
      Japio
      Japio
    • Smartmeter sensors

      Energy companies in Holland started the deployment of the so-called Smartmeters for electricity and gas. These meters have the ability to be read out.

      Information on how to do the read-out I use this site for reference.

      Note that the data output of the meter needs to be inverted, there are various possiblities to do this. These can be found here.

      All info on how to connect the meter to your arduino is in the source code:
      0_1470081395831_SmartMeterSensor20.ino

      Enjoy it, and if you have any remarks or improvements, post a response to this topic.

      posted in My Project
      Japio
      Japio
    • RE: ESP8266 gateway + WebServer = Awesome!

      @hek Indeed, the ESP has both plenty of processing power and memory compared to the arduino.

      This implementing a receive method, is that a method I can implement in my sketch, with a specific name and signature, and it will be called automatically (like the indication handler)? or does it require changes in de library code? Sounds promising, I can just take out the data I need and store it in a separate structure until the webpage is requested.

      Another thing I found "somewhere on the Internet" is an ESP8266 program that, when the wifi connection is not established, or the stored network SSID and password are empty, places the ESP in Access point mode. You can connect to this wifi network and configure the wifi settings. That way you don't need your SSID and password in the sketch.

      Too many things to do, and too little time I am afraid.😀

      posted in Development
      Japio
      Japio
    • RE: Using before()

      Hi,

      Indeed it is 2.0.1 beta.

      Yes, I 'll try tonight, and report back on the result.

      Thanks.

      posted in Development
      Japio
      Japio