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
  1. Home
  2. Troubleshooting
  3. nodeMCU, MY_GATEWAY_ESP8266 and Temp Sensor

nodeMCU, MY_GATEWAY_ESP8266 and Temp Sensor

Scheduled Pinned Locked Moved Troubleshooting
22 Posts 6 Posters 8.2k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mysensors-6043M Offline
    mysensors-6043M Offline
    mysensors-6043
    wrote on last edited by
    #3

    Hi since I am new to mysensors, I starting with examples, don't have much experience right now.
    Here is my sketch.

    #include <ESP8266WiFi.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #include <EEPROM.h>
    #include <SPI.h>
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 115200
    
    // Enables and select radio type (if attached)
    #define MY_RADIO_RFM69
    #define MY_GATEWAY_ESP8266
    
    // Enable UDP communication
    #define MY_USE_UDP
    #define MY_PORT 5003 
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    #define MY_ESP8266_HOSTNAME "nodeMCUTemperatureECM"   
    
    // How many clients should be able to connect to this gateway (default 1)
    #define MY_GATEWAY_MAX_CLIENTS 2
    
    // Controller ip address. Enables client mode (default is "server" mode). 
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 152
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    
    // Enable Inclusion mode button on gateway
    // #define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
    // Flash leds on rx/tx/err
    // #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    // #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Led pins used if blinking feature is enabled above
    #define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    
    #include <WiFiUdp.h>
    #include <MyConfig.h>
    #include <MySensors.h>
    
    #define ONE_WIRE_BUS 2
    #define MAX_ATTACHED_DS18B20 4
    int numSensors=0;
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
    
    void setup() {
      //sensors.begin();
    }
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("nodeMCUTemperatureECM", "1.0");
      // Fetch the number of attached temperature sensors  
      numSensors = sensors.getDeviceCount();
      
      Serial.print("----------------- # of Sensors found >>> ");
      Serial.println(numSensors);
      
      // Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
         present(i, S_TEMP);
      }
    }
    
    void loop() {
      // Send locally attached sensors data here
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures(); // Send the command to get temperatures
      Serial.println("DONE");
      delay(1000);
    }
    
    
    mfalkviddM 1 Reply Last reply
    0
    • mysensors-6043M Offline
      mysensors-6043M Offline
      mysensors-6043
      wrote on last edited by
      #4

      Ok, thank You. So how I declare MySensor gw; in mysensors Version 2 ?

      mfalkviddM 1 Reply Last reply
      0
      • mysensors-6043M mysensors-6043

        Hi since I am new to mysensors, I starting with examples, don't have much experience right now.
        Here is my sketch.

        #include <ESP8266WiFi.h>
        #include <OneWire.h>
        #include <DallasTemperature.h>
        #include <EEPROM.h>
        #include <SPI.h>
        
        // Enable debug prints to serial monitor
        #define MY_DEBUG
        
        // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
        #define MY_BAUD_RATE 115200
        
        // Enables and select radio type (if attached)
        #define MY_RADIO_RFM69
        #define MY_GATEWAY_ESP8266
        
        // Enable UDP communication
        #define MY_USE_UDP
        #define MY_PORT 5003 
        
        // Set the hostname for the WiFi Client. This is the hostname
        // it will pass to the DHCP server if not static.
        #define MY_ESP8266_HOSTNAME "nodeMCUTemperatureECM"   
        
        // How many clients should be able to connect to this gateway (default 1)
        #define MY_GATEWAY_MAX_CLIENTS 2
        
        // Controller ip address. Enables client mode (default is "server" mode). 
        // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
        #define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 152
        
        // Enable inclusion mode
        #define MY_INCLUSION_MODE_FEATURE
        
        // Enable Inclusion mode button on gateway
        // #define MY_INCLUSION_BUTTON_FEATURE
        // Set inclusion mode duration (in seconds)
        #define MY_INCLUSION_MODE_DURATION 60 
        // Digital pin used for inclusion mode button
        #define MY_INCLUSION_MODE_BUTTON_PIN  3 
        
        // Flash leds on rx/tx/err
        // #define MY_LEDS_BLINKING_FEATURE
        // Set blinking period
        // #define MY_DEFAULT_LED_BLINK_PERIOD 300
        
        // Led pins used if blinking feature is enabled above
        #define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
        #define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
        #define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
        
        #include <WiFiUdp.h>
        #include <MyConfig.h>
        #include <MySensors.h>
        
        #define ONE_WIRE_BUS 2
        #define MAX_ATTACHED_DS18B20 4
        int numSensors=0;
        OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
        DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
        
        void setup() {
          //sensors.begin();
        }
        
        void presentation() {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("nodeMCUTemperatureECM", "1.0");
          // Fetch the number of attached temperature sensors  
          numSensors = sensors.getDeviceCount();
          
          Serial.print("----------------- # of Sensors found >>> ");
          Serial.println(numSensors);
          
          // Present all sensors to controller
          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
             present(i, S_TEMP);
          }
        }
        
        void loop() {
          // Send locally attached sensors data here
          Serial.print("Requesting temperatures...");
          sensors.requestTemperatures(); // Send the command to get temperatures
          Serial.println("DONE");
          delay(1000);
        }
        
        
        mfalkviddM Online
        mfalkviddM Online
        mfalkvidd
        Mod
        wrote on last edited by
        #5

        @mysensors-6043 looks like you have used some of the DallasTemperatureSensor example, is that correct?

        If that is the case, it seems heavily modified. Lots of includes that shouldn't be there (MyConfig.h for example) and sensors.begin is called from the wrong funchtion (should be before(), not setup() )

        Try starting with the bare example and get that working. Then extend it little by little while checking that it still works.

        1 Reply Last reply
        0
        • mysensors-6043M Offline
          mysensors-6043M Offline
          mysensors-6043
          wrote on last edited by
          #6

          ok, I'll give it another try. Learning by doing :-)
          Starting with the ESP8266 example and adding the Dallas Temp parts ?

          mfalkviddM 1 Reply Last reply
          0
          • mysensors-6043M mysensors-6043

            Ok, thank You. So how I declare MySensor gw; in mysensors Version 2 ?

            mfalkviddM Online
            mfalkviddM Online
            mfalkvidd
            Mod
            wrote on last edited by
            #7

            @mysensors-6043 said:

            Ok, thank You. So how I declare MySensor gw; in mysensors Version 2 ?

            You don't. It is not used in MySensors 2. https://forum.mysensors.org/topic/4276/converting-a-sketch-from-1-5-x-to-2-0-x describes the differences between version 1.5 and 2.0

            1 Reply Last reply
            0
            • mysensors-6043M mysensors-6043

              ok, I'll give it another try. Learning by doing :-)
              Starting with the ESP8266 example and adding the Dallas Temp parts ?

              mfalkviddM Online
              mfalkviddM Online
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #8

              @mysensors-6043 said:

              ok, I'll give it another try. Learning by doing :-)

              Yes that is a good approach. To me it is the best and the most fun way to learn.

              Starting with the ESP8266 example and adding the Dallas Temp parts ?

              The Dallas example works on several platforms, it is not esp specific. It does require a specific version of the Dallas library though. You can get the example and the library by downloading https://github.com/mysensors/MySensorsArduinoExamples

              1 Reply Last reply
              0
              • mysensors-6043M Offline
                mysensors-6043M Offline
                mysensors-6043
                wrote on last edited by
                #9

                Hey great, I started with a new sketch and did what You recommended. I get the number of sensors now without exception and stack trace. On a good way now I guess. Many thank's and best regards from Switzerland

                1 Reply Last reply
                0
                • mysensors-6043M mysensors-6043

                  Using mysensors 2.0 on a nodeMCU, I can deploy the DS18B20 to read temp values. Secondly using the mysensors Gateway works to join the WLAN and sending Messages to iobroker mysensors instance.

                  Serial log
                  0;255;3;0;9;TSM:INIT
                  0;255;3;0;9;TSM:RADIO:OK
                  0;255;3;0;9;TSM:GW MODE
                  0;255;3;0;9;TSM:READY
                  scandone
                  f 0, scandone
                  state: 0 -> 2 (b0)
                  state: 2 -> 3 (0)
                  state: 3 -> 5 (10)
                  add 0
                  aid 1
                  cnt

                  connected with ho..., channel 1
                  dhcp client start...
                  chg_B1:-40
                  .ip:192.168.1.103,mask:255.255.0.0,gw:192.168.1.1
                  .IP: 192.168.1.103
                  ----------------- # of Sensors found >>> 1
                  0;255;3;0;9;No registration required
                  0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1

                  iobroker log

                  mysensors-0 2016-09-30 07:24:06.103 info Version from 192.168.1.103 :1.1
                  mysensors-0 2016-09-30 07:24:06.101 info Name from 192.168.1.103 :nodeMCUTemperatureECM
                  mysensors-0 2016-09-30 07:24:06.095 info Connected 192.168.1.103:5003

                  As soon as I call sensor.begin() I get an exception and stack trace

                  Fatal exception 9(LoadStoreAlignmentCause):
                  epc1=0x402028e8, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000002f, depc=0x00000000

                  Exception (9):
                  epc1=0x402028e8 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000002f depc=0x00000000

                  ctx: cont
                  sp: 3ffef850 end: 3ffefaf0 offset: 01a0

                  stack>>>
                  3ffef9f0: 00000000 00008000 3ffeeabc 00000030
                  3ffefa00: 3ffe8be0 3ffefa10 000000ff 40225ad5
                  3ffefa10: ffffffff 0000138b 3fff13fc 40228271
                  3ffefa20: 3fff1774 3fff1238 3fff13fc 3ffeeabc
                  3ffefa30: 3fffdad0 3ffefbaf 3ffefb98 40203d38
                  3ffefa40: 000000f3 00000000 3ffefb6c 402047be
                  3ffefa50: 000000e7 3ffefe38 3ffefb98 4020295d
                  3ffefa60: 00000001 3ffefe38 3ffefb98 3ffeeabc
                  3ffefa70: 3ffefbb0 00000001 3ffefb98 40202a44
                  3ffefa80: 3fffdad0 00000000 00000006 40202316
                  3ffefa90: 00000000 3ffefd04 3ffeea80 3ffeeabc
                  3ffefaa0: 3fffdad0 00000000 00000005 40204b2c
                  3ffefab0: 3fffdad0 00000000 3ffeea80 40204d19
                  3ffefac0: 00000000 00000000 3ffeea80 40204460
                  3ffefad0: 3fffdad0 00000000 3ffeea80 40204e34
                  3ffefae0: feefeffe feefeffe 3ffeead0 40100114
                  <<<stack<<<

                  ets Jan 8 2013,rst cause:2, boot mode:(3,6)

                  load 0x4010f000, len 1384, room 16
                  tail 8
                  chksum 0x2d
                  csum 0x2d
                  v3de0c112
                  ~ld
                  0;255;3;0;9;Starting gateway (RRNGE-, 2.0.0)
                  0;255;3;0;9;TSM:INIT
                  0;255;3;0;9;TSM:RADIO:OK
                  0;255;3;0;9;TSM:GW MODE
                  0;255;3;0;9;TSM:READY
                  scandone
                  f 0, scandone
                  state: 0 -> 2 (b0)
                  state: 2 -> 3 (0)
                  state: 3 -> 5 (10)
                  add 0
                  aid 1
                  cnt

                  I found another script where MySensor gw; is declared, but this gives me an error. And in the same example #include MySensor.h is declared. But I have to use #include MySensors.h. Is this a matter of mysensors Version ?

                  YveauxY Offline
                  YveauxY Offline
                  Yveaux
                  Mod
                  wrote on last edited by
                  #10

                  @mysensors-6043 said:

                  As soon as I call sensor.begin() I get an exception and stack trace

                  Fatal exception 9(LoadStoreAlignmentCause):

                  This is usually caused by a library which is not (fully) compatible with 32-bit processors (AVR is 8-bit).
                  The MySensors library has been ported to ESP8266 and does not throw such exceptions (to my knowledge).
                  If the DS18B20 library @mfalkvidd pointed at does not solve your issue I would search the net for other people having issues with the same library & ESP8266, to see how they solved it.

                  http://yveaux.blogspot.nl

                  1 Reply Last reply
                  0
                  • mysensors-6043M Offline
                    mysensors-6043M Offline
                    mysensors-6043
                    wrote on last edited by
                    #11

                    ok, yes lokks like this. A soon as I try to get temp values then I run into an exception again.

                    void loop() {
                      // Send locally attached sensors data here
                      Serial.print("Requesting temperatures...");
                      sensors.requestTemperatures(); // Send the command to get temperatures
                      Serial.println("DONE");
                      delay(1000);
                    }
                    
                    1 Reply Last reply
                    0
                    • korttomaK Offline
                      korttomaK Offline
                      korttoma
                      Hero Member
                      wrote on last edited by
                      #12

                      @mysensors-6043 said:

                      Do not use:

                       delay(1000);
                      

                      Instead try:

                      wait(1000);
                      
                      
                      • Tomas
                      1 Reply Last reply
                      0
                      • scalzS Offline
                        scalzS Offline
                        scalz
                        Hardware Contributor
                        wrote on last edited by
                        #13

                        @mysensors-6043

                        As @Yveaux said, it can be lib compatibility with esp.
                        So If you want to try, I use this lib for ds18b20, with other mcus : http://www.pjrc.com/teensy/td_libs_OneWire.html (his stuff is neat).
                        I have not tried with esp8266 though, but i'm pretty sure it works ;) there are defines for esp8266 which are not present in mysensors git..

                        1 Reply Last reply
                        0
                        • mysensors-6043M Offline
                          mysensors-6043M Offline
                          mysensors-6043
                          wrote on last edited by
                          #14

                          ok, i'll try, hmmmm how to import / use this lib ?

                          1 Reply Last reply
                          0
                          • scalzS Offline
                            scalzS Offline
                            scalz
                            Hardware Contributor
                            wrote on last edited by scalz
                            #15

                            @mysensors-6043
                            how did you import Mysensors? ;) that's the same for every lib :)
                            So if you don't find it in lib manager, then download it and unzip it in your lib folder. restart arduino. go to examples. simple.
                            You will find this one in lib manager (look at the one with Paul PaulStoffregen contributor). or download it from his git

                            1 Reply Last reply
                            0
                            • CravecodeC Offline
                              CravecodeC Offline
                              Cravecode
                              wrote on last edited by
                              #16

                              @mysensors-6043,
                              Have you been able to confirm that you get temperature readings on the sensor? I would try to simplify your sketch to rule things out.

                              Here's what I'd do, in the following order:

                              • Remove all MySensors related code and just get the sensor reading to the serial monitor.
                              • I see you're looping over several temperature sensors on the node, simplify this, only read one for starters.
                              • Verify your gateway is on the network by using telnet or netcat. I.e.: nc xxx.xxx.xxx.xxx 5003
                              • Try just getting your node to "present" to the gateway. Reading the sensor debug via the serial monitor and watch the gateway via netcat.
                              1 Reply Last reply
                              0
                              • mysensors-6043M Offline
                                mysensors-6043M Offline
                                mysensors-6043
                                wrote on last edited by
                                #17

                                Hi, yes, the Hardware is ok. running a Dallas example script shows the temperature from the sensor.
                                The Gateway is on the Network, I see a DHCP request and get Messages on the iobroker.

                                1 Reply Last reply
                                0
                                • CravecodeC Offline
                                  CravecodeC Offline
                                  Cravecode
                                  wrote on last edited by
                                  #18

                                  @mysensors-6043,
                                  The sketch you posted looks like you combined the sensors with the NodeMCU, is this true? Is this NodeMCU acting as a gateway as well?

                                  1 Reply Last reply
                                  0
                                  • mysensors-6043M Offline
                                    mysensors-6043M Offline
                                    mysensors-6043
                                    wrote on last edited by mysensors-6043
                                    #19

                                    yes, but i'm not shure whether this is correct
                                    All I Need is a sensor that sends the temperature via WLAN to UDP Port 5003 of the iobroker (acting as Controller)

                                    Could also be an Arduino Nano with a Radio, e.g. NRF24L01

                                    1 Reply Last reply
                                    0
                                    • CravecodeC Offline
                                      CravecodeC Offline
                                      Cravecode
                                      wrote on last edited by
                                      #20

                                      @mysensors-6043,
                                      The normal setup involves 3 pieces:

                                      1. The sensor (aka node) emitting data via RF using something like a NRF24L01
                                      2. A gateway that receives the sensor data via the RF module (NRF24L01) and sends it to a controller over ethernet or wifi.
                                      3. A controller to manage connected nodes and present data to the user.

                                      It seems like you're combining the sensor and gateway into one device. If this is the case, I think you can comment out the #define MY_RADIO_RFM69 line as there is no radio connected. I don't know how this plays into the registration process of a sensor. There is no ID getting associated to the sensor because this is a gateway.

                                      Maybe someone else can chime in who knows whether it's okay to combine the gateway and sensor into one device. If so, how is registration and ID assignment handled?

                                      @mysensors-6043,
                                      Post a updated version of your sketch.

                                      1 Reply Last reply
                                      0
                                      • mysensors-6043M Offline
                                        mysensors-6043M Offline
                                        mysensors-6043
                                        wrote on last edited by
                                        #21

                                        ok, looks better, I included the library from Paul Stoffregen and commented out #define MY_RADIO_RFM69.
                                        So far no exception. I still can join my home WLAN, but sensor data can not be read.
                                        All I Need is a temp sensor and send the data do a iobroker instance.

                                        The question is whether I'm on the right track with a nodeMCU ?

                                        1 Reply Last reply
                                        0
                                        • mysensors-6043M Offline
                                          mysensors-6043M Offline
                                          mysensors-6043
                                          wrote on last edited by
                                          #22

                                          Hey Folks
                                          Thank's a lot, the issue is solved. nodeMCU as a gateway measures the temperature, pass it over to an iobroker / mysensors instance. There with a JavaScript, I set a Homematic System Variable which is displayed in the iPad.
                                          So now, I know, when the coffee machine has the right temp.

                                          cheers

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          20

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

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