Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
JapioJ

Japio

@Japio
Hardware Contributor
About
Posts
23
Topics
7
Shares
0
Groups
1
Followers
0
Following
0

Posts

Recent Best Controversial

  • ESP8266 gateway + WebServer = Awesome!
    JapioJ Japio

    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!

    Development

  • ESP8266 gateway + WebServer = Awesome!
    JapioJ Japio

    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.

    Development

  • Smartmeter sensors
    JapioJ Japio

    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.

    My Project

  • ESP8266 gateway + WebServer = Awesome!
    JapioJ Japio

    @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.:grinning:

    Development

  • Using before()
    JapioJ Japio

    Hi,

    Indeed it is 2.0.1 beta.

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

    Thanks.

    Development
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular