Nodemcu 0.9 + MQTT gateway + TEMP + Motion Sensor



  • Hi,

    I'm having my first bash at mysensors and a total newbie to all of this so please excuse any simple oversights. I feel a bit sheepish just posting this as there are a few examples of what I am trying to do but after a day of head scratching i feel i need to ask for help.

    The story so far:

    I have a bunch of nodemcu's lying around so thought I would make some multi purpose wifi/ mqtt sensors.

    First up I mashed the mqtt gateway and DHT sketches together.

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     *
     * DESCRIPTION
     * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker.
     * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
     *
     * LED purposes:
     * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
     * nRF24L01+  ESP8266
     * VCC        VCC
     * CE         GPIO4
     * CSN/CS     GPIO15
     * SCK        GPIO14
     * MISO       GPIO12
     * MOSI       GPIO13
     *
     * Not all ESP8266 modules have all pins available on their external interface.
     * This code has been tested on an ESP-12 module.
     * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
     * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
     * - Connect GPIO15 via 10K pulldown resistor to GND
     * - Connect CH_PD via 10K resistor to VCC
     * - Connect GPIO2 via 10K resistor to VCC
     * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
     *
      * Inclusion mode button:
     * - Connect GPIO5 via switch to GND ('inclusion switch')
     *
     * Hardware SHA204 signing is currently not supported!
     *
     * Make sure to fill in your ssid and WiFi password below for ssid & pass.
     */
    
    
    // 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 9600
    
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266
    
    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "XXXXXXXXXXXXXXXX"
    //#define MY_MQTT_PASSWORD "XXXXXXXXXXXXXXXX"
    
    // Set WIFI SSID and password
    #define MY_ESP8266_SSID "XXXXXXXXXXXXXXX"
    #define MY_ESP8266_PASSWORD "XXXXXXXXXXX"
    
    // 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 "mqtt-sensor-gateway"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,178,87
    
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    
    // MQTT broker ip address.
    #define MY_CONTROLLER_IP_ADDRESS 10, 10, 0, 10
    
    // The MQTT broker port to to open
    #define MY_PORT 1883
    
    /*
    // 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
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    #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 <ESP8266WiFi.h>
    #include <MySensors.h>
    #include <SPI.h>
    #include <DHT.h>
    
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 2
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures
    #define SENSOR_TEMP_OFFSET 0
    
    // Sleep time between sensor updates (in milliseconds)
    // Must be >1000ms for DHT22 and >2000ms for DHT11
    static const uint64_t UPDATE_INTERVAL = 60000;
    //const unsigned long SLEEP_TIME = 60000; 
    
    // Force sending an update of the temperature after n sensor reads, so a controller showing the
    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
    // the value didn't change since;
    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
    static const uint8_t FORCE_UPDATE_N_READS = 10;
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    
    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    DHT dht;
    
    
    
    void presentation()
    { 
      // Send the sketch version information to the gateway
      sendSketchInfo("TemperatureAndHumidity", "1.1");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
    
      metric = getConfig().isMetric;
    }
    
    
    void setup()
    {
      dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
      if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
        Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
      }
      // Sleep for the time of the minimum sampling period to give the sensor time to power up
      // (otherwise, timeout errors might occure for the first reading)
      wait(dht.getMinimumSamplingPeriod());
    }
    
    
    void loop()      
    {  
      // Force reading sensor, so it works also after sleep()
      dht.readSensor(true);
    
      // Get temperature from DHT library
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT!");
      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        temperature += SENSOR_TEMP_OFFSET;
        send(msgTemp.set(temperature, 1));
    
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      } else {
        // Increase no update counter if the temperature stayed the same
        nNoUpdatesTemp++;
      }
    
      // Get humidity from DHT library
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
        lastHum = humidity;
        // Reset no updates counter
        nNoUpdatesHum = 0;
        send(msgHum.set(humidity, 1));
    
        #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
        #endif
      } else {
        // Increase no update counter if the humidity stayed the same
        nNoUpdatesHum++;
      }
    
      // Sleep for a while to save energy
      wait(UPDATE_INTERVAL); 
    }
    

    This is working great. So I have a working temp / humidity sensor.

    Ploughing on I mashed my working mqtt dht example with the motion example and realisied i might have bitten off more than I can chew...

    Stepping back I thought ok just try MQTT + Motion Here's the sketch.

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     *
     * DESCRIPTION
     * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker.
     * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
     *
     * LED purposes:
     * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     *
     * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
     * nRF24L01+  ESP8266
     * VCC        VCC
     * CE         GPIO4
     * CSN/CS     GPIO15
     * SCK        GPIO14
     * MISO       GPIO12
     * MOSI       GPIO13
     *
     * Not all ESP8266 modules have all pins available on their external interface.
     * This code has been tested on an ESP-12 module.
     * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
     * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
     * - Connect GPIO15 via 10K pulldown resistor to GND
     * - Connect CH_PD via 10K resistor to VCC
     * - Connect GPIO2 via 10K resistor to VCC
     * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
     *
      * Inclusion mode button:
     * - Connect GPIO5 via switch to GND ('inclusion switch')
     *
     * Hardware SHA204 signing is currently not supported!
     *
     * Make sure to fill in your ssid and WiFi password below for ssid & pass.
     */
    
    
    // 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 9600
    
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266
    
    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway2-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway2-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-2"
    
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    
    // Set WIFI SSID and password
    #define MY_ESP8266_SSID "XXXXXXXXXXXXXXXX"
    #define MY_ESP8266_PASSWORD "XXXXXXXXXXXXXXXXX"
    
    // 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 "mqtt-sensor-gateway"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,178,87
    
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    
    // MQTT broker ip address.
    #define MY_CONTROLLER_IP_ADDRESS 10, 10, 0, 10
    
    // The MQTT broker port to to open
    #define MY_PORT 1883
    
    /*
    // 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
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    #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 <ESP8266WiFi.h>
    #include <MySensors.h>
    
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 2   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define CHILD_ID 1   // Id of the sensor child
    
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()
    {
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Motion Sensor", "1.0");
    
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID, S_MOTION);
    }
    
    void loop()
    {
        // Read digital motion value
        bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
    
        Serial.println(tripped);
        send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
    
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
    }
    

    The node comes up and mqtt gateway registers with mybroker.

    See the serial log here:

    oÈHìè‰CGH,xI$ø0;255;3;0;9;MCO:BGN:INIT GW,CP=R-NGE--,VER=2.1.0
    scandone
    f 0, scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 8
    cnt 
    
    connected with LakeNET, channel 1
    dhcp client start...
    .ip:10.10.0.235,mask:255.255.255.0,gw:10.10.0.1
    .IP: 10.10.0.235
    0;255;3;0;9;MCO:BGN:STP
    0;255;3;0;9;MCO:REG:NOT NEEDED
    0;255;3;0;9;MCO:BGN:INIT OK,TSP=NA
    IP: 10.10.0.235
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;MQTT connected
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/255/0/0/17
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/255/3/0/11
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/255/3/0/12
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/0/0/1
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    1
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    0;255;3;0;9;MCO:SLP:WUP=-2
    0
    0;255;3;0;9;Sending message on topic: mygateway2-out/0/1/1/0/16
    0;255;3;0;9;MCO:SLP:MS=120000,SMS=0,I1=2,M1=3,I2=255,M2=255
    pm open,type:2 0
    

    But the sketch that looks like it should sleep for 2 mins if there is no motion (i have the sensor face down) but the sketch just keeps runnning away.

    I am not sure if its the code or something to do with the hardware / how I am wired. Just not sure about this whole interrupt thing.

    0_1483770379775_IMG_20170107_142648.jpg

    Any pointers will be gratefully received.



  • Just browsing through your code since I have a similar setup with a mqtt gateway with a few sensors and had the same problem. The thing is that a gateway shouldn't sleep thus I believe the sleep() function is not working (without looking at the source code). I replaced sleep() with wait() and have it running on usb power.


  • Admin

    @Efflon @Sam-Lake The sleeping function for ESP8266 HW is currently not implemented, hence following debug output:

    0;255;3;0;9;MCO:SLP:WUP=-2
    

    WUP=-2 indicates that sleeping is not possible.



  • With esp8266 and MQTT you are not in the right corner at MySensors. You might want to check out ESPEasy:

    http://letscontrolit.com/wiki/index.php/ESPEasy



  • I have a similar setup: MySensor nodes running on NodeMcu/ESP8266 and each using an MQTT client gateway to send sensor status directly to my MQTT broker running on a Raspberry pi alongside Home Assistant. And I also had to replace sleep() with counters in the loop() code. Those error codes are described here.

    I spent many hours learning and configuring HA so sticking to that for now. Their community, like MySensors are very helpful.


 

264
Online

7.5k
Users

8.3k
Topics

89.7k
Posts