Navigation

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

    Japio

    @Japio

    Hardware Contributor

    14
    Reputation
    23
    Posts
    799
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Japio Follow
    Hardware Contributor

    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

    Latest posts made by Japio

    • Fritzing and OpenHardware.IO

      Hi all,

      Probably the in the wrong category, but I am in the process of adding my project to Openhardware.io, and run into the following problem:

      I created the schematic and PCB in fritzing. How do I export the BOM list to OpenHardware.io? As only csv format is accepted, and fritzing only produces HTML files

      posted in Hardware
      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
    • RE: Using before()

      One more thing I just found out: if I take out the walking-light from the setup_led() it works fine as well.

      As this takes some time, might there be some kind of race condition during initialization of the MySensors stack?

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

      I installed 2.2.0 beta and indeed something has changed, but nothing that helps me:

      Placed the setup_led() in before():

      0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGE--,VER=2.2.0-beta
      0;255;3;0;9;MCO:BGN:BFR
      scandone
      state: 0 -> 2 (b0)
      state: 2 -> 3 (0)
      state: 3 -> 5 (10)
      add 0
      aid 8
      cnt 
      
      connected with XXXX, channel 6
      dhcp client start...
      ip:192.168.X.x,mask:255.255.255.0,gw:192.168.X.X
      Going to MySensors Application mode
      - Broker Ip Address: 192.168.X.X
      - Broker Port: 1883
      - Network name: XXXX
      0;255;3;0;9;TSF:LRT:OK
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;TSF:WUR:MS=0
      0;255;3;0;9;TSM:INIT:TSP OK
      0;255;3;0;9;TSM:INIT:GW MODE
      0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
      0;255;3;0;9;MCO:REG:NOT NEEDED
      f r0, scandone
      .....0;255;3;0;9;TSF:MSG:READ,20-20-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
      0;255;3;0;9;TSF:MSG:BC
      0;255;3;0;9;TSF:MSG:FPAR REQ,ID=20
      0;255;3;0;9;TSF:PNG:SEND,TO=0
      0;255;3;0;9;TSF:CKU:OK
      0;255;3;0;9;TSF:MSG:GWL OK
      0;255;3;0;9;TSF:MSG:SEND,0-0-20-20,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
      ...0;255;3;0;9;TSF:MSG:READ,20-20-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
      0;255;3;0;9;TSF:MSG:PINGED,ID=20,HP=1
      0;255;3;0;9;TSF:MSG:SEND,0-0-20-20,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
      ..0;255;3;0;9;TSF:MSG:READ,20-20-0,s=6,c=1,t=17,pt=7,l=5,sg=0:2660
      0;255;3;0;9;TSF:MSG:READ,20-20-0,s=7,c=1,t=17,pt=7,l=5,sg=0: 0
      pm open,type:2 0
      .....................0;255;3;0;9;TSF:MSG:READ,20-20-0,s=6,c=1,t=17,pt=7,l=5,sg=0:2590
      0;255;3;0;9;TSF:MSG:READ,20-20-0,s=7,c=1,t=17,pt=7,l=5,sg=0: 0
      .....................0;255;3;0;9;TSF:MSG:READ,20-20-0,s=6,c=1,t=17,pt=7,l=5,sg=0:2590
      0;255;3;0;9;TSF:MSG:READ,20-20-0,s=7,c=1,t=17,pt=7,l=5,sg=0: 0
      ..................
      

      Well, anyway. I moved the setup_led function to the setup() so I am ok for now. But this is still a weird situation.

      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
    • Using before()

      Hi,

      I have created a "MyVersion" of the ESP8266 Mqtt gateway. To show detailed state of the gateway (things like message received, message sent, wifi connection and strength) I connected a Neopixel Stick (8 RGB leds) to the ESP8266.

      To initialize the leds I created a function setup_leds() that initializes the Neopixel library and does some sort of walking light across the RGB colors of each LED.

      So far no problems.

      However, when I call the setup_leds() from the void before() function, the gateway is not able to get an IP address. If I move this call to setup() it does get an ip address.

      This output is with setup_leds() in before():

      0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGE--,VER=2.0.1-beta
      0;255;3;0;9;MCO:BGN:BFR
      scandone
      state: 0 -> 2 (b0)
      state: 2 -> 3 (0)
      state: 3 -> 5 (10)
      add 0
      aid 8
      cnt 
      
      connected with XXXX, channel x
      dhcp client start...
      ip:192.168.X.XX,mask:255.255.255.0,gw:192.168.X.XXX
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;TSM:INIT:TSP OK
      0;255;3;0;9;TSM:INIT:GW MODE
      0;255;3;0;9;TSM:READY
      f r0, scandone
      .pm open,type:2 0
      ............................................................................
      

      This reproduces 100% of the time. My question is: What is the problem here? Is it possible to use the before? Are there time constraints on placing code in before()?

      posted in Development
      Japio
      Japio
    • ESP8266 MQTT client dynamically changing MQTT broker settings

      Hi,

      I am working on an ESP8266 MQTT gateway with a web interface to allow th user to configure settings. One of these settings is the MQTT broker IP address and port number.

      In the before() I read out the IP address from EEPROM and want to set it in the gateway software, and not as normally done by defining MY_CONTROLLER_IP_ADDRESS.

      Is it possible to do this?

      I already tried to declare _ethernetControllerIP as external. This doesn't work.
      Also tried to skip de definition MY_CONTROLLER_IP_ADDRESS and declar it in the gateway sketch. Didn't work either.😥

      posted in Development
      Japio
      Japio
    • RE: Smartmeter sensors

      @rwanrooy : I used AltSoftSerial for the smartmeter sensor, because it has only 1 uart for serial communication, which is used for firmware upload/download. That is why I used the software alternative. But if it actually is the arduino MEGA 2560, it has 4 uarts, one for the firmware download (serial 0), but the other 3 are at your service (looking at the documentation, I don't know the details.)

      These hardware ports should better be able to handle the 115200 baud.

      posted in My Project
      Japio
      Japio
    • RE: Smartmeter sensors

      @sincze You can find it on: https://github.com/Japio74/MysSmartmeterGateway

      |t currently already is 2.0.0.

      Enjoy it!

      posted in My Project
      Japio
      Japio
    • RE: Smartmeter sensors

      @sincze : Good to see you used my program! 😃 I also changed some things, I added some sleeps in between the presentation messages, as I got a lot of failures during presentation. And I removed all the timers between sending updates.

      Now, I send the current usage and production on every new update, and the rest only when the timestamp of the gasmeter changes (at the start of every hour) I also commented out sending the timestamp of the gasmeter and main switch.

      posted in My Project
      Japio
      Japio