My Slim 2AA Battery Node


  • Hardware Contributor



  • Thanks, it worked!
    Sorry that I couldn't find the post you linked..

    alt text



  • Are there any guides on how to assemble the 2.0 version?
    How should I, as I beginner, find this out?
    I know about the schematics and the BOM, but, for example, I could only find R1, C1, C2 and C3 marked. The schematics shows C4 and C5, just an example - how do I find where those go?

    Thanks in advance,
    hugo



  • @hugows C4 goes over the ground and VCC of the NRF radio. I'm not sure about but C5, from some pictures I have seen I think it goes in the same place as C4 but I may be wrong. I have left that out without an issue.

    OP - this board is great! it take the pain out of soldering the radio to a pro mini / nano. I really like these.



  • @thazlett144 Thanks. like this then?

    alt text

    One more thing: can I mount R1, C1, C2, C3 on the bottom side? My "height requirements" aren't as strict, since my cable duct is almost 2cm tall.

    --

    To check, I will be soldering this 8 components in this order:

    • R1
    • C1
    • C2
    • C3
    • C4 electrolitic (then bend it)
    • Atmega socket
    • NRF24 radio
    • 6 pin angled connector


  • C4 in your picture looks correct to me. You could put C4 up on the edge under where the radio would be as well. You have VCC up on the edge. I think the pins adjacent to that are ground too. EDIT: I think I replied before you edited your picture 🙂

    You can solder the components underneath if you need to yes. I don't see why that would be an issue.


  • Hardware Contributor

    I'll add the C4 and C5 ref-silk to the list of requests for improvements.



  • @m26872 C5 would be in paralllel to C4, right?
    Also, those are the capacitors for improving the radio transmission, correct?

    Thanks for this awesome board, @m26872!


  • Hardware Contributor

    @hugows Yes, C4 is the standard recommended cap on the radio module supply and should be between Vcc and Gnd as near the radio as possible. The chinese clones are known to be very supply noise sensitive. C5 is of low ESR type and there to further increase the filtering. In theory it should be even closer than C4.

    A battery supply is stable by nature and you should probably stay fine without some of the caps in other cases as well. The design is intended to provide flexibility and margin in general. It's easy to throw in a few extra parts and then maybe avoid some troubleshooting.



  • I've set up two sensors with 2 reed switches and 1 HTU21D attached. When I was testing them around 60 cm away from my gateway they worked very fine. Now I moved them to their final destination which is around 8-10 meters away from the gateway and now they don't reach the gateway anymore. Any idea what could cause this? Any way to increase the range?



  • @siod
    Is there any obstruction between the nodes and the gateway? Trees, walls, etc? Depending on what is in between the radios you can dramatically lose signal.



  • each one goes around a corner and so one wall is partly between the nodes and the gateway and it´s not even concrete. I have one node in my basement attached to an arduino nano and I have no range problems...

    The batteries are all fully loaded.

    edit:
    I would like to post my Node sketch as well as my gateway sketch and MyConfig.h. Maybe there is some optimization potential:

    Node sktech:

    // Sensor Node Schlafzimmer mit HTU21D Temp/Hum Sensor, Fensterkontakte an Interrupt PINS Digital 5&6. Sleep Time 15 Minutwn, wake up wenn Fenster geöffnet/geschlossen wird.
    #define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen
    // Define Node ID
    #define MY_NODE_ID 4
    
    //Batterysensor
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int oldBatteryPcnt = 0;
    #define CHILD_ID_BATT 7
    
    //Kontaktschalter
    //#include <Bounce2.h>
    #define CHILD1_ID 1 // Kontaktschalter 1
    #define CHILD2_ID 2 // Kontaktschalter 2
    #define BUTTON1_PIN  2  // Kontaktschalter 1
    #define BUTTON2_PIN  3  // Kontaktschalter 2
    int oldValueReed1=-1;
    int oldValueReed2=-1;
    
    //Tempsensor
    #include <SparkFunHTU21D.h>
    #include <Wire.h>
    #define CHILD_ID_HUM 3
    #define CHILD_ID_TEMP 4
    unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
    
    #include <MySensors.h>
    #include <SPI.h>
    
    //tempsensor
    HTU21D myHumidity;
    float lastTemp;
    float lastHum;
    //boolean metric = true; 
    
    //Messages
    //Battery
    MyMessage msgbatt(CHILD_ID_BATT,V_VOLTAGE);
    // Kontaktschalter
    MyMessage msgReed1(CHILD1_ID,V_TRIPPED); // Kontaktschalter 1
    MyMessage msgReed2(CHILD2_ID,V_TRIPPED); // Kontaktschalter 2
    //TempMessage
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    //Presentation; present sensors to gateway!
    void presentation(){
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Küche Messstation", "2.0", true);
        
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(CHILD1_ID, S_DOOR); 
      present(CHILD2_ID, S_DOOR); 
        
      //Tempsensor
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP); 
      //metric = getConfig().isMetric;
    
      //Battery
      present(CHILD_ID_BATT,V_VOLTAGE);
    }
    
    //Setup
    void setup()  
    {  
      //Serial.begin(9600);
      Serial.println("Hello!");
      //Batterysensor
         // use the 1.1 V internal reference
    #if defined(__AVR_ATmega2560__)
       analogReference(INTERNAL1V1);
    #else
       analogReference(INTERNAL);
    #endif
    
    //Tempsensor
      Serial.println("Setting up TempSensor...");
      myHumidity.begin();
      Serial.println("...done!");
    
    // Setup Kontaktschalter 1
      pinMode(BUTTON1_PIN,INPUT);
        // Activate internal pull-up
      digitalWrite(BUTTON1_PIN,HIGH);
    // Setup Kontaktschalter 2
      pinMode(BUTTON2_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON2_PIN,HIGH);
    }
    
    //Starte den Loop
    void loop() 
    {
      //Batterysensor
      // get the battery Voltage
      delay(1000);
       int sensorValue = analogRead(BATTERY_SENSE_PIN);
       #ifdef DEBUG
       #endif
       
       // 1M, 470K divider across battery and using internal ADC ref of 1.1V
       // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
       // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
       // 3.44/1023 = Volts per bit = 0.003363075
       float batteryV  = sensorValue * 0.003363075;
       int batteryPcnt = sensorValue / 10;
    
       #ifdef DEBUG
       Serial.print("Battery Voltage: ");
       Serial.print(batteryV);
       Serial.println(" V");
    
       Serial.print("Battery percent: ");
       Serial.print(batteryPcnt);
       Serial.println(" %");
       #endif
    
       if (oldBatteryPcnt != batteryPcnt) {
         // Power up radio after sleep
         sendBatteryLevel(batteryPcnt,true);
         send(msgbatt.set(batteryPcnt),true);
         oldBatteryPcnt = batteryPcnt;
       }
       
      //Kontakstschalter 1
       // Short delay to allow buttons to properly settle
      sleep(10);
      // Get the update value
      int valueReed1 = digitalRead(BUTTON1_PIN);
     
      if (valueReed1 != oldValueReed1) {
         // Send in the new value
         send(msgReed1.set(valueReed1==HIGH ? 1 : 0),true);
         Serial.println("Button 1 geschaltet");
         oldValueReed1 = valueReed1;
      }
      //Kontakstschalter 2
      // Get the update value
      int valueReed2 = digitalRead(BUTTON2_PIN);
     
      if (valueReed2 != oldValueReed2) {
         // Send in the new value
         send(msgReed2.set(valueReed2==HIGH ? 1 : 0),true);
         Serial.println("Button 2 geschaltet");
         oldValueReed2 = valueReed2;
      }
     
     //Tempsensor
    Serial.println("Starte Messung...");
      
        float temp = myHumidity.readTemperature();
    
      if (isnan(temp)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temp != lastTemp) {
        lastTemp = temp;
        send(msgTemp.set(temp, 1),true);
        Serial.print("T: ");
        Serial.println(temp);
      }
      
     float humd = myHumidity.readHumidity();
      if (isnan(humd)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humd != lastHum) {
          lastHum = humd;
          send(msgHum.set(humd, 1),true);
          Serial.print("H: ");
          Serial.println(humd);
      }
    
     Serial.println("Sleep...");
     sleep(BUTTON1_PIN - 2, CHANGE, BUTTON2_PIN - 2, CHANGE, SLEEP_TIME); //sleep a bit 
      
    } 
    
    
    

    Gateway sketch:

    #include <SPI.h>
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enables and select radio type (if attached)
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_GATEWAY_MQTT_CLIENT
    
    // Set this nodes subscripe 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"
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4  
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with 
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
    #endif  
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN 
      #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN 
      #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,1,51
    
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // MQTT broker ip address or url. Define one or the other. 
    //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 50
    
    // The MQTT broker port to to open 
    #define MY_PORT 1883      
    
     /*
    // Flash leds on rx/tx/err
    #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // 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 
    
    // Uncomment to override default HW configurations
    //#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 <Ethernet.h>
    #include <MySensors.h>
    
    void setup() { 
    }
    
    void presentation() {
      // Present locally attached sensors here    
    }
    
    
    void loop() {
      // Send locally attech sensors data here
    }
    

    MyConfig.h

    /*
     * 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.
     */
    
    /**
     * @file MyConfig.h
     *
     * MySensors specific configurations
     */
    #ifndef MyConfig_h
    #define MyConfig_h
    #include <stdint.h>
    
    
    /**********************************
    *  Serial and debug options
    ***********************************/
    
    // Enable MY_DEBUG in sketch to show debug prints. This option will add a lot to the size of the
    // final sketch but is helpful to see what is actually is happening during development
    //#define MY_DEBUG
    
    // Enable MY_SPECIAL_DEBUG in sketch to activate I_DEBUG messages if MY_DEBUG is disabled.
    // I_DEBUG requests are:
    // R: routing info (only repeaters): received msg XXYY (as stream), where XX is the node and YY the routing node
    // V: CPU voltage
    // F: CPU frequency
    // M: free memory
    // E: clear MySensors EEPROM area and reboot (i.e. "factory" reset)
    //#define MY_SPECIAL_DEBUG
    
    // Enable MY_DEBUG_VERBOSE_SIGNING flag for verbose debug prints related to signing.
    // Requires DEBUG to be enabled.
    // This will add even more to the size of the final sketch!
    //#define MY_DEBUG_VERBOSE_SIGNING
    
    // Enable this in sketch if you want to use TX(1), RX(0) as normal I/O pin
    //#define MY_DISABLED_SERIAL
    
    // Enable MY_CORE_ONLY flag if you want to use core functions without loading the framework
    //#define MY_CORE_ONLY
    
    // Turn off debug if serial pins is used for other stuff
    #ifdef MY_DISABLED_SERIAL
    #undef MY_DEBUG
    #endif
    
    /**
     * @def MY_BAUD_RATE
     * @brief Serial output baud rate (debug prints and serial gateway speed).
     */
    #ifndef MY_BAUD_RATE
    #define MY_BAUD_RATE 115200
    #endif
    
    // Disables over-the-air reset of node
    //#define MY_DISABLE_REMOTE_RESET
    
    /**********************************
    *  Radio selection and node config
    ***********************************/
    
    // Selecting uplink transport layer is optional (for a gateway node).
    
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    
    /**
    * @def MY_TRANSPORT_SANITY_CHECK
    * @brief If enabled, node will check transport in regular intervals to detect HW issues and re-initialize in case of failure. This feature is enabled for all repeater nodes (incl. GW)
    */
    //#define MY_TRANSPORT_SANITY_CHECK
    /**
    * @def MY_TRANSPORT_SANITY_CHECK_INTERVAL
    * @brief Interval (in ms) of transport sanity checks
    */
    #ifndef MY_TRANSPORT_SANITY_CHECK_INTERVAL
    #define MY_TRANSPORT_SANITY_CHECK_INTERVAL ((uint32_t)60000)
    #endif
    /**
     * @def MY_REGISTRATION_FEATURE
     * @brief If enabled, node has to register to gateway/controller before allowed to send sensor data.
     */
    #define MY_REGISTRATION_FEATURE
    
     /**
     * @def MY_REGISTRATION_RETRIES
     * @brief Number of registration retries if no reply received from GW/controller
     */
    
    #ifndef MY_REGISTRATION_RETRIES
    #define MY_REGISTRATION_RETRIES 3
    #endif
    
     /**
     * @def MY_REGISTRATION_DEFAULT
     * @brief Node registration default - this applies if no registration response is recieved from controller
     */
    
    #define MY_REGISTRATION_DEFAULT true
    
     /**
     * @def MY_REGISTRATION_CONTROLLER
     * @brief If enabled, node registration request has to be handled by controller
     */
     // #define MY_REGISTRATION_CONTROLLER
    
     /**
     * @def MY_CORE_COMPATIBILITY_CHECK
     * @brief If enabled, library compatibility is checked during node registration. Incompatible libraries are unable to send sensor data.
     */
    #define MY_CORE_COMPATIBILITY_CHECK
    
    /**
     * @def MY_NODE_ID
     * @brief Node id defaults to AUTO (tries to fetch id from controller).
     */
    #ifndef MY_NODE_ID
    #define MY_NODE_ID AUTO
    #endif
    
    /**
     * @def MY_PARENT_NODE_ID
     * @brief Node parent defaults to AUTO (tries to find a parent automatically).
     */
    #ifndef MY_PARENT_NODE_ID
    #define MY_PARENT_NODE_ID AUTO
    #endif
    
    /**
     * @def MY_PARENT_NODE_IS_STATIC
     * @brief Enable MY_PARENT_NODE_IS_STATIC to disable fall back if parent node fails
     */
    //#define MY_PARENT_NODE_IS_STATIC
    
    // Enables repeater functionality (relays messages from other nodes)
    // #define MY_REPEATER_FEATURE
    
    /**
     * @def MY_SMART_SLEEP_WAIT_DURATION
     * @brief The wait period before going to sleep when using smartSleep-functions.
     *
     * This period has to be long enough for controller to be able to send out
     * potential buffered messages.
     */
    #ifndef MY_SMART_SLEEP_WAIT_DURATION
    #define MY_SMART_SLEEP_WAIT_DURATION 500
    #endif
    
    /**********************************
    *  Over the air firmware updates
    ***********************************/
    
    // Enable MY_OTA_FIRMWARE_FEATURE in sketch to allow safe over-the-air firmware updates.
    // This feature requires external flash and the DualOptiBoot boot-loader.
    // Note: You can still have OTA FW updates without external flash but it
    // requires the MYSBootloader and disabled MY_OTA_FIRMWARE_FEATURE
    //#define MY_OTA_FIRMWARE_FEATURE
    
    /**
     * @def MY_OTA_FLASH_SS
     * @brief Slave select pin for external flash.
     */
    #ifndef MY_OTA_FLASH_SS
    #define MY_OTA_FLASH_SS 8
    #endif
    
    /**
     * @def MY_OTA_FLASH_JDECID
     * @brief Flash jdecid.
     */
    #ifndef MY_OTA_FLASH_JDECID
    #define MY_OTA_FLASH_JDECID 0x1F65
    #endif
    
    
    /**********************************
    *  Gateway config
    ***********************************/
    
    /**
     * @def MY_GATEWAY_MAX_RECEIVE_LENGTH
     * @brief Max buffersize needed for messages coming from controller.
     */
    #ifndef MY_GATEWAY_MAX_RECEIVE_LENGTH
    #define MY_GATEWAY_MAX_RECEIVE_LENGTH 100
    #endif
    
    /**
     * @def MY_GATEWAY_MAX_SEND_LENGTH
     * @brief Max buffer size when sending messages.
     */
    #ifndef MY_GATEWAY_MAX_SEND_LENGTH
    #define MY_GATEWAY_MAX_SEND_LENGTH 120
    #endif
    
    /**
     * @def MY_GATEWAY_MAX_CLIENTS
     * @brief Max number of parallel clients (sever mode).
     */
    #ifndef MY_GATEWAY_MAX_CLIENTS
    #define MY_GATEWAY_MAX_CLIENTS 1
    #endif
    
    
    
    /**********************************
    *  Information LEDs blinking
    ***********************************/
    // This feature enables LEDs blinking on message receive, transmit
    // or if some error occurred. This was commonly used only in gateways,
    // but now can be used in any sensor node. Also the LEDs can now be
    // disabled in the gateway.
    
    #define MY_LEDS_BLINKING_FEATURE
    
    // The following setting allows you to inverse the blinking feature MY_LEDS_BLINKING_FEATURE
    // When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
    // off when blinking
    
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // The following defines can be used to set the port pin, that the LED is connected to
    // If one of the following is defined here, or in the sketch, MY_LEDS_BLINKING_FEATURE will be
    // enabled by default. (Replace x with the pin number you have the LED on)
    //#define MY_DEFAULT_ERR_LED_PIN x
    //#define MY_DEFAULT_TX_LED_PIN x
    //#define MY_DEFAULT_RX_LED_PIN x
    
    /**********************************************
    *  Gateway inclusion button/mode configuration
    **********************************************/
    // Enabled inclusion mode feature
    //#define MY_INCLUSION_MODE_FEATURE
    
    // Enables inclusion-mode button feature on the gateway device
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Disable inclusion mode button if inclusion mode feature is not enabled
    #ifndef MY_INCLUSION_MODE_FEATURE
    #undef MY_INCLUSION_BUTTON_FEATURE
    #endif
    
    /**
     * @def MY_INCLUSION_MODE_BUTTON_PIN
     * @brief The default input pin used for the inclusion mode button.
     */
    #ifndef MY_INCLUSION_MODE_BUTTON_PIN
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_INCLUSION_MODE_BUTTON_PIN 5
    	#else
    		#define MY_INCLUSION_MODE_BUTTON_PIN 3
    	#endif
    #endif
    
    /**
     * @def MY_INCLUSION_MODE_DURATION
     * @brief Number of seconds (default one minute) inclusion mode should be enabled.
     */
    
    #ifndef MY_INCLUSION_MODE_DURATION
    #define MY_INCLUSION_MODE_DURATION 60
    #endif
    
    /**
     * @def MY_INCLUSION_BUTTON_PRESSED
     * @brief The logical level indicating a pressed inclusion mode button.
     */
    #if defined(MY_INCLUSION_BUTTON_EXTERNAL_PULLUP)
    #define MY_INCLUSION_BUTTON_PRESSED HIGH
    #else
    #define MY_INCLUSION_BUTTON_PRESSED LOW
    #endif
    
    /**********************************
    *  Message Signing Settings
    ***********************************/
    /**
     * @def MY_SIGNING_ATSHA204
     * @brief Enables HW backed signing functionality in library.
     *
     * For any signing related functionality to be included, this define or @ref MY_SIGNING_SOFT has to be enabled.
     */
    //#define MY_SIGNING_ATSHA204
    
    /**
     * @def MY_SIGNING_SOFT
     * @brief Enables SW backed signing functionality in library.
     *
     * For any signing related functionality to be included, this define or @ref MY_SIGNING_ATSHA204 has to be enabled.
     */
    //#define MY_SIGNING_SOFT
    
    /**
     * @def MY_SIGNING_REQUEST_SIGNATURES
     * @brief Enable this to inform gateway to sign all messages sent to this node.
     *
     * If used for a gateway, gateway will only request signatures from nodes that in turn
     * request signatures from gateway.
     */
    //#define MY_SIGNING_REQUEST_SIGNATURES
    
    /**
     * @def MY_VERIFICATION_TIMEOUT_MS
     * @brief Define a suitable timeout for a signature verification session
     *
     * Consider the turnaround from a nonce being generated to a signed message being received
     * which might vary, especially in networks with many hops. 5s ought to be enough for anyone.
     */
    #ifndef MY_VERIFICATION_TIMEOUT_MS
    #define MY_VERIFICATION_TIMEOUT_MS 5000
    #endif
    
    /**
     * @def MY_SIGNING_NODE_WHITELISTING
     * @brief Enable to turn on whitelisting
     *
     * When enabled, a signing node will salt the signature with it's unique signature and nodeId.<br>
     * The verifying node will look up the sender in a local table of trusted nodes and
     * do the corresponding salting in order to verify the signature.<br>
     * For this reason, if whitelisting is enabled on one of the nodes in a sign-verify pair, both
     * nodes have to implement whitelisting for this to work.<br>
     * Note that a node can still transmit a non-salted message (i.e. have whitelisting disabled)
     * to a node that has whitelisting enabled (assuming the receiver does not have a matching entry
     * for the sender in it's whitelist). The whitelist to use is defined as the value of the flag.
     */
    //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
    
    /**
     * @def MY_SIGNING_ATSHA204_PIN
     * @brief Atsha204 default pin setting
     *
     * Pin where ATSHA204 is attached
     */
    #ifndef MY_SIGNING_ATSHA204_PIN
    #define MY_SIGNING_ATSHA204_PIN 17
    #endif
    
    /**
     * @def MY_SIGNING_SOFT_RANDOMSEED_PIN
     * @brief Pin used for random generation in soft signing
     *
     * Do not connect anything to this when soft signing is enabled
     */
    #ifndef MY_SIGNING_SOFT_RANDOMSEED_PIN
    #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
    #endif
    
    /**********************************
    *  RS485 Driver Defaults
    ***********************************/
    
    /**
     * @def MY_RS485_BAUD_RATE
     * @brief The RS485 BAUD rate.
     */
    #ifndef MY_RS485_BAUD_RATE
    #define MY_RS485_BAUD_RATE 9600
    #endif
    
    /**
     * @def MY_RS485_MAX_MESSAGE_LENGTH
     * @brief The maximum message length used for RS485.
     */
    #ifndef MY_RS485_MAX_MESSAGE_LENGTH
    #define MY_RS485_MAX_MESSAGE_LENGTH 40
    #endif
    
    /**********************************
    *  NRF24L01P Driver Defaults
    ***********************************/
    
    // Enables RF24 encryption (all nodes and gateway must have this enabled, and all must be personalized with the same AES key)
    //#define MY_RF24_ENABLE_ENCRYPTION
    
    /**
     * @def MY_DEBUG_VERBOSE_RF24
     * @brief Enable MY_DEBUG_VERBOSE_RF24 flag for verbose debug prints related to the RF24 driver. Requires DEBUG to be enabled.
     */
    //#define MY_DEBUG_VERBOSE_RF24
    
    /**
     * @def MY_RF24_SPI_MAX_SPEED
     * @brief MY_RF24_SPI_MAX_SPEED to overrule default nRF24L01+ SPI speed.
     */
    //#define MY_RF24_SPI_MAX_SPEED 4000000
    
    /**
     * @def MY_RF24_CE_PIN
     * @brief Default RF24 chip enable pin setting. Override in sketch if needed.
     */
    #ifndef MY_RF24_CE_PIN
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_RF24_CE_PIN 4
    	#elif defined(ARDUINO_ARCH_SAMD)
    		#define MY_RF24_CE_PIN 27
    	#else
    		#define MY_RF24_CE_PIN 9
    	#endif
    #endif
    
    /**
     * @def MY_RF24_CS_PIN
     * @brief Default RF24 chip select pin setting. Override in sketch if needed.
     */
    #ifndef MY_RF24_CS_PIN
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_RF24_CS_PIN 15
    	#elif defined(ARDUINO_ARCH_SAMD)
    		#define MY_RF24_CS_PIN 3
    	#else
    		#define MY_RF24_CS_PIN 10
    	#endif
    #endif
    
    /**
     * @def MY_RF24_PA_LEVEL
     * @brief Default RF24 PA level. Override in sketch if needed.
     */
    #ifndef MY_RF24_PA_LEVEL
    #define MY_RF24_PA_LEVEL RF24_PA_MAX
    #endif
    
    /**
     * @def MY_RF24_CHANNEL
     * @brief RF channel for the sensor net, 0-125.
     * Frequence: 2400 Mhz - 2525 Mhz Channels: 126
     * http://www.mysensors.org/radio/nRF24L01Plus.pdf
     * 0 => 2400 Mhz (RF24 channel 1)
     * 1 => 2401 Mhz (RF24 channel 2)
     * 76 => 2476 Mhz (RF24 channel 77)
     * 83 => 2483 Mhz (RF24 channel 84)
     * 124 => 2524 Mhz (RF24 channel 125)
     * 125 => 2525 Mhz (RF24 channel 126)
     * In some countries there might be limitations, in Germany for example only the range 2400,0 - 2483,5 Mhz is allowed
     * http://www.bundesnetzagentur.de/SharedDocs/Downloads/DE/Sachgebiete/Telekommunikation/Unternehmen_Institutionen/Frequenzen/Allgemeinzuteilungen/2013_10_WLAN_2,4GHz_pdf.pdf
     */
    #ifndef MY_RF24_CHANNEL
    #define MY_RF24_CHANNEL	76
    #endif
    
    /**
     * @def MY_RF24_DATARATE
     * @brief RF24 datarate (RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps or RF24_2MBPS for 2Mbps).
     */
    #ifndef MY_RF24_DATARATE
    #define MY_RF24_DATARATE RF24_250KBPS
    #endif
    
    /**
     * @def MY_RF24_BASE_RADIO_ID
     * @brief RF24 radio network identifier.
     *
     * This acts as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
     */
    #ifndef MY_RF24_BASE_RADIO_ID
    #define MY_RF24_BASE_RADIO_ID 0x00,0xFC,0xE1,0xA8,0xA8
    #endif
    
    /**
     * @def MY_RF24_ADDR_WIDTH
     * @brief RF24 address width.
     *
     * This defines the width of the base address.
     */
    #ifndef MY_RF24_ADDR_WIDTH
    #define MY_RF24_ADDR_WIDTH 5
    #endif
    
    /**
     * @def MY_RF24_SANITY_CHECK
     * @brief RF24 sanity check to verify functional RF module
     *
     * This reads back and compares configuration registers. Disable if using non-P modules
     */
    #define MY_RF24_SANITY_CHECK
    
    // Enable SOFTSPI for NRF24L01, useful for the W5100 Ethernet module
    //#define MY_SOFTSPI
    
    /**
     * @def MY_SOFT_SPI_SCK_PIN
     * @brief Soft SPI SCK pin.
     */
    #ifndef MY_SOFT_SPI_SCK_PIN
    #define MY_SOFT_SPI_SCK_PIN 14
    #endif
    
    /**
     * @def MY_SOFT_SPI_MISO_PIN
     * @brief Soft SPI MISO pin.
     */
    #ifndef MY_SOFT_SPI_MISO_PIN
    #define MY_SOFT_SPI_MISO_PIN 16
    #endif
    
    /**
     * @def MY_SOFT_SPI_MOSI_PIN
     * @brief Soft SPI MOSI pin.
     */
    #ifndef MY_SOFT_SPI_MOSI_PIN
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    /**********************************
    *  RFM69 Driver Defaults
    ***********************************/
    
    /**
     * @def MY_RFM69_FREQUENCY
     * @brief RFM69 frequency to use (RF69_433MHZ for 433MHz, RF69_868MHZ for 868MHz or RF69_915MHZ for 915MHz).
     *
     * This must match the hardware version of the RFM69 radio.
     */
    #ifndef MY_RFM69_FREQUENCY
    #define MY_RFM69_FREQUENCY   RF69_868MHZ
    #endif
    
    /**
     * @def MY_IS_RFM69HW
     * @brief Enable this if you're running the RFM69HW model.
     */
    //#define MY_IS_RFM69HW
    
    /**
     * @def MY_RFM69HW
     * @brief Set to true if @ref MY_IS_RFM69HW is set.
     */
    #ifdef MY_IS_RFM69HW
    	#define MY_RFM69HW true
    #else
    	#define MY_RFM69HW false
    #endif
    
    /**
     * @def MY_RFM69_NETWORKID
     * @brief RFM69 Network ID. Use the same for all nodes that will talk to each other.
     */
    #ifndef MY_RFM69_NETWORKID
    #define MY_RFM69_NETWORKID     100
    #endif
    
    /**
     * @def MY_RF69_IRQ_PIN
     * @brief RF69 IRQ pin.
     */
    #ifndef MY_RF69_IRQ_PIN
    #define MY_RF69_IRQ_PIN RF69_IRQ_PIN
    #endif
    
    /**
     * @def MY_RF69_SPI_CS
     * @brief RF69 SPI chip select pin.
     */
    #ifndef MY_RF69_SPI_CS
    #define MY_RF69_SPI_CS RF69_SPI_CS
    #endif
    
    /**
     * @def MY_RF69_IRQ_NUM
     * @brief RF69 IRQ pin number.
     */
    #ifndef MY_RF69_IRQ_NUM
    	#if defined(ARDUINO_ARCH_ESP8266)
    		#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
    	#else
    		#define MY_RF69_IRQ_NUM RF69_IRQ_NUM
    	#endif
    #endif
    
    // Enables RFM69 encryption (all nodes and gateway must have this enabled, and all must be personalized with the same AES key)
    //#define MY_RFM69_ENABLE_ENCRYPTION
    
    /**************************************
    * Ethernet Gateway Transport  Defaults
    ***************************************/
    
    // The gateway options available
    //#define MY_GATEWAY_W5100
    //#define MY_GATEWAY_ENC28J60
    //#define MY_GATEWAY_ESP8266
    
    /**
     * @def MY_PORT
     * @brief The Ethernet TCP/UDP port to open on controller or gateway.
     */
    #ifndef MY_PORT
    #define MY_PORT 5003
    #endif
    
    // Static ip address of gateway (if this is disabled, DHCP will be used)
    //#define MY_IP_ADDRESS 192,168,178,66
    
    // Enables UDP mode for Ethernet gateway (W5100)
    //#define MY_USE_UDP
    
    /**
     * @def MY_IP_RENEWAL_INTERVAL
     * @brief DHCP, default renewal setting in milliseconds.
     */
    #ifndef MY_IP_RENEWAL_INTERVAL
    #define MY_IP_RENEWAL_INTERVAL 60000
    #endif
    
    /**
     * @def MY_MAC_ADDRESS
     * @brief Ethernet MAC address.
     *
     * This needs to be unique on the network.
     */
    #ifndef MY_MAC_ADDRESS
    #define MY_MAC_ADDRESS 0xAD, 0xAD, 0xBE, 0xAD, 0xFE, 0xED
    #endif
    
    // Controller ip-address, if this is defined, gateway will act as a client trying to contact controller on MY_PORT.
    // If MY_CONTROLLER_IP_ADDRESS is left un-defined, gateway acts as server allowing incoming connections.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    /**
     * @defgroup MyLockgrp MyNodeLock
     * @ingroup internals
     * @{
     * @brief The node lock feature is a security related feature. It locks a node that suspect itself for being
     * under some form of attack.
     *
     * This is achieved by having a counter stored in EEPROM which decrements when suspicious activity is detected.
     * If the counter reaches 0, node will not work anymore and will transmit a @ref I_LOCKED message to the
     * gateway/controller with 30m intervals. Payload is a string with a reason for the locking.
     * The string is abbreviated to accomodate a signature. The following abbreviations exist at the moment:
     * - LDB (Locked During Boot)
     * - TMNR (Too Many Nonce Requests)
     * - TMFV (Too Many Failed Verifications)
     *
     * Typically, the counter only decrements when suspicious activity happens in a row.
     * It is reset if legit traffic is present.
    
     * Examples of malicious activity are:
     * - Repeatedly incorrectly checksummed OTA firmware
     * - Repeated requests for signing nonces without properly signed messages arriving
     * - Repeatedly failed signature verifications
     *
     * If counter reaches zero, node locks down and EEPROM has to be erased/reset to reactivate node.
     * Node can also be unlocked by grounding a pin (see @ref MY_NODE_UNLOCK_PIN).
     *
     * The size of the counter can be adjusted using @ref MY_NODE_LOCK_COUNTER_MAX.
     *
     * @def MY_NODE_LOCK_FEATURE
     * @brief Enable this to activate intrusion prevention mechanisms on the node.
     */
    //#define MY_NODE_LOCK_FEATURE
    
    /**
     * @def MY_NODE_UNLOCK_PIN
     * @brief By grounding this pin durig reset of a locked node, the node will unlock.
     *
     * If using a secure bootloader, grounding the pin is the only option to reactivate the node.
     * If using stock Android bootloader or a DualOptiBoot it is also possible to download a sketch
     * using serial protocol to erase EEPROM to unlock the node.
     */
    #ifndef MY_NODE_UNLOCK_PIN
    #define MY_NODE_UNLOCK_PIN 14
    #endif
    
    /**
     * @def MY_NODE_LOCK_COUNTER_MAX
     * @brief Maximum accepted occurances of suspected malicious activity in a node.
     *
     * Counter decrements on reoccuring incidents but resets if legitimate behaviour is identified.
     */
    #ifndef MY_NODE_LOCK_COUNTER_MAX
    #define MY_NODE_LOCK_COUNTER_MAX 5
    #endif
    /** @}*/ // Node lock group
    
    #endif
    
    // Doxygen specific constructs, not included when built normally
    // This is used to enable disabled macros/definitions to be included in the documentation as well.
    #if DOXYGEN
    #define MY_SIGNING_ATSHA204
    #define MY_SIGNING_SOFT
    #define MY_SIGNING_REQUEST_SIGNATURES
    #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
    #define MY_IS_RFM69HW
    #define MY_PARENT_NODE_IS_STATIC
    #define MY_REGISTRATION_CONTROLLER
    #define MY_DEBUG_VERBOSE_RF24
    #define MY_TRANSPORT_SANITY_CHECK
    #endif
    

    edit2:

    Now I get this this from the node on my gateway´s serial monitor:

    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:SANCHK:OK
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    0;255;3;0;9;!TSP:MSG:SEND 0-0-4-4 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=fail:0
    0;255;3;0;9;TSP:MSG:READ 4-4-255 s=255,c=3,t=7,pt=0,l=0,sg=0:
    0;255;3;0;9;TSP:MSG:BC
    0;255;3;0;9;TSP:MSG:FPAR REQ (sender=4)
    0;255;3;0;9;TSP:CHKUPL:OK (FLDCTRL)
    0;255;3;0;9;TSP:MSG:GWL OK
    
    

    and so on...

    edit: I restarted my gateway and the nodes, it is working for a while, but after 1 or 2 days 1 or more nodes freeze. Does anybody else have equal problems?



  • I have ordered the 2.0 boards, they are on their way to my home 🙂

    I'm plannign to use them as :

    • temperature node
    • door sensor

    For the door sensor, can you tell me if I'm good :
    I have to use a 1MOhm resistor between the pin of atmega and one wire of the reed switch ? So I will have the longest battery life (my atmegas are burned at 1 Mhz or 8 Mhz)

    Am I right ?


  • Hardware Contributor

    @carmelo42
    Thanks for your support by ordering. I actually recieved another 50+ share credit transfer from DirtyPCBs today. It'll be donated to MySensors right away.

    If you look at post 116 you'll see the I used a 10Mohm pull-up between Vcc and atmega input pin. Reed switch connects between Gnd and input pin.



  • @m26872 said:

    @carmelo42
    Thanks for your support by ordering. I actually recieved another 50+ share credit transfer from DirtyPCBs today. It'll be donated to MySensors right away.

    If you look at post 116 you'll see the I used a 10Mohm pull-up between Vcc and atmega input pin. Reed switch connects between Gnd and input pin.

    Thanks to you for providing us theses files 🙂

    Ok, my mistake (I juste received my 10 MOhm resistor 😉
    Perfect, I just have to wait now for the little yellow packet 😉



  • I have received yesterday my little packet from DirtyPCB 🙂
    11 PCBs, so 33 sensors 🙂

    I'm just wondering where the C5 capactior will go on the board .. Can't figure out 😞



  • @carmelo42: maybe this helps, all Cs and the R assembled!
    0_1476615490017_20161016_125251.jpg



  • ups... C5 is also not there on my board,it shoud be parallel to C4!



  • @jeti said:

    ups... C5 is also not there on my board,it shoud be parallel to C4!

    is your sensor working without C5 ?



  • @m26872 is it possible to send the sketch in the atmega on board ? using an FTDI serial/usb ?



  • @carmelo42 yes



  • @jeti said:

    @carmelo42 yes

    I have this serial/usb adapter :
    https://img1.picload.org/image/ldrrddg/deekrobot-isp.png

    Can you tell me how I connect it to my node ? (noob question I guess ... but I don't want to burn my node 😞 )



  • @carmelo42 said:

    @jeti said:

    @carmelo42 yes

    I have this serial/usb adapter :
    https://img1.picload.org/image/ldrrddg/deekrobot-isp.png

    Can you tell me how I connect it to my node ? (noob question I guess ... but I don't want to burn my node 😞 )

    I have found the answer myself with the schematic 😉

    Have you ever tried to power the node with 1 x CR2032 battery ?

    I have tried, but the node doesn't send anything further than 5 meters ...



  • I would like to know if your nodes are working all fine. I have the problem that my nodes freeze after a day or sometimes after a week.



  • @siod my temperature nodes work good, but my relay one doesn't work 😢

    Do you have any logs when it freezes ?



  • @carmelo42 no, unfortunately I don´t have any logs, any idea how to create logs?



  • @siod said:

    @carmelo42 no, unfortunately I don´t have any logs, any idea how to create logs?

    maybe if you keep your node connected to your computer with USB to serial adapter ?



  • mmh, no, that would mean I would have to run my computer for maybe 2 weeks 24/7...

    I guess it has somehting to do with the sleep function, the device seems to nat wake up after a while for some reason



  • So i got the boards and build them and they work perfect.

    One thing i couldn't figure out is why do i get relatively high current consumption, when the node is sleeping i get 1.5mA and not 5.8uA as in mentioned in this post.

    I use 8MHz internal clock and the sleep function and nothing is connected to the node.

    Can someone help?


  • Hero Member

    @dpressle Can you post the sketch?



  • Thanks, i see its 6.8 uA now, i had something wrong with my measurements 😞



  • It took me a while, but I just figured out how to get a bootloader burned onto the chip and I'm ready to make my slim nodes! Which board type in Arduino IDE do I use to program the chip once I'm using the 6 pin header after it's installed in the PCB?


  • Hardware Contributor

    @JonnyDev13 Make a new board type by editing "boards.txt". There's an example in the first post.



  • Hi there! I need to buy some PCBs on Dirty PCBs but the URL http://dirtypcbs.com/view.php?share=13847&accesskey= seems broken. Any ideas? Thanks!


  • Hardware Contributor

    @รอเรือ Apparently they've moved to a new site. Perhaps you can try this link: http://dev.dirtypcbs.com/store/designer/details/m26872/663/myslim2aabatterynodepcbv2-0panelized

    I think you must have a user account and login first. Please report back if it's working or not.

    Edit: Wrong link the first time.



  • Thanks @m26872

    That link didn't work either. However, by browsing all the shared PCBs I found this URL That link is accessible without logging in first.

    Cheers


  • Hardware Contributor

    @รอเรือ Thanks a lot! All links are now changed.



  • Hey im building my first slim node and i wonder if someone has a sketch for 2 reed switches? i have found the sketch for only 1 reed switch in this thread. Im going to use it for my mailbox. How long do u think it can run on 2x aa batteries?
    Do i have to add 2x 10M resistors? or doesnt it work with external resistors then using more then 1 reed switch?


  • Hardware Contributor

    @Eawo The example sketch should fit your needs. link Change the pull-ups activation to Low if you use external ones.
    I'd expect battery life 5-10 years depending on things such mailbox opening frequency, use of heartbeat signal, battery self discharge and climate.


  • Hardware Contributor

    @Eawo Using internal resistors will only give you a few months battery time. One external pull-up for each switch will work and 1M resistors or any arbitrary "high" value is just as good.



  • Thanks
    ok now my problem is uploading the sketch it wont work on 1mhz bootloader i tried both a and b hex and the 2 diffrent Board.txt.
    I get it to work with the 8Mhz breadboard bootloader.
    But then using 1mhz bootloaders it always timesout



  • after a few hours frustration i went donwstars grabbed 2x new atmega328p breadboards and wolla everything works :). I Think i burned my first to putting them in the socket wrong.



  • i have wired everything but it wont work for me 😞 i have solder the 2 reed switch from gnd to d2 and gnd to d3. and ive done the same 2 1m resistors. I can see the node in domotics but no activity then i open and close.


  • Hardware Contributor

    @Eawo
    The reed switches need to sit between GND and D2 or D3 as you have connected.

    The 1M pull up resistors need to connect between Vcc and D2 or D3.

    This way D2 or D3 are electrically connected to Vcc when the switches are open (pulled high). When the switches close, D2 and D3 get connected to GND.



  • I only come down to 12µA with one reed switch, 1MOhm pullup, 1Mhz bootloader and the binarySwitchSleepSketch. Measured with two different multimeters. This is nearly ten times higher than in the first posting. Changing all internal pullups to LOW doesn't change anything.

    Is there a way to optimize the power consumption or is it "good enough" ?


  • Hero Member

    @rollercontainer For sub 8uA consumption you need to go to "deep sleep" where the internal timers of the processor are disabled. Only wake up on interrupt. sleep( interrupt1, FALLING, 0);


  • Hardware Contributor

    @rollercontainer - I just build a slimnode and 13uA is without anything connected what i can reach as well.
    For comparison i aim below 100uA when i do this with pro mini and they last around a year with 2xAA so my guess is 13uA is good enough.



  • @sundberg84: Thanks, so I will stick to my 12µA 🙂

    @AWI: I am using sleep with Interrupt as in this example:

    sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
    

    https://github.com/mysensors/MySensors/blob/development/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino#L120


  • Hero Member

    @rollercontainer Your sleep looks good. Did you remove this piece of code?

    // Activate internal pull-ups
    	digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
    	digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
    

    Take a look at this thread for a < 1 uA consumption...



  • Since a few months I am very interested in Mysensors and this PCB. I have ordered the PCB and components to build some sensors as for a home security system. For experimental purpose I build one on a breadboard and that is working fine.
    A few days ago I started to solder the components on the PCB. The firs one is working fine, but the next sensors have an issue with the transceiver. After 3 boards failing I soldered one without the transceiver. Then I tested it by holding the transceiver at the board and it was working fine. After soldering the transceiver again a not working board.

    I tested one board by pressing another transceiver on top of the soldered one and I saw some communication in MYSController. The ATMega is still working on the breadboard. The PCB and Breadboard are powered by the same batterypack.

    Before soldering I tested all the transceivers with my breadboard and they are working fine. I am also using an anti-static bracelet.

    What am I doing wrong??
    0_1486492736615_1.jpg


  • Hardware Contributor

    Have you desoldered one radio to see if it's back alive again? What's your distance to Gateway? Maybe some filtering or antenna effect by your fingers and breadboard? What if you leave a working radio on the breadboard then just connect it with wires to PCB?



  • @m26872
    Distance is about 50cm. They are both on my desk. If testing then I do not tough the sensor. Just when trien pressing a radio an a non function radio.
    I tried to de-solder the radio but did not succeed. Cut the pins, removed them and soldered wires to it. Connected to a new radio. Strange part is that the on very irregular basis message are received in MYSController. Also with a radio which is functioning well on the breadboard


  • Hardware Contributor

    @aneco - 50cm is a big problem for me! Its to close and the node - gw is having a hard time communicating for some reason. I wish I didnt set my gw up in the workplace where i build because every time im testing some node I have to go to the next room. Maybe you could try this?


  • Hardware Contributor

    @m26872 - I made this (but with the big motiondec, because my small ones didnt work so well due to clone/copy). Thanks for PCB, instructions and tutorials. Great work!

    Node is running at 13uA without motiondetector attached and 90-95uA with the motion dec attached. Im happy with that and ill see how long the batteries last. When my small motion dec arrive I can just switch over.

    0_1486553881423_1.jpg



  • @sundberg84
    The node on the breadboard is on the same desk and same distance to gateway. The same for my first sensor. And both are working well. Only issue with 4 sensors a soldered afterwords.

    Just remember now that I used for the first sensor other solder. But do not think that this is causing the issue or .....



  • Hello i wonder how you do then you put sensors outside mine stop work after a few hours i guess its becouse its cold here and maybe humitiy? then i take them inside for while it start working again. i think i need a waterprofe case or something


  • Mod

    Well, batteries and components have working temperatures so it depends how cold it gets over there



  • Its one in the garage it is never below 0- C this one was alive the longest the other one was dead in 2-3days and maybe as coldest it was 10- C. I'm starting to think it's something wrong with the gateway


  • Mod

    If you reset either node or gateway, does it go back to work or what?



  • No it doesn't only sometimes


  • Mod

    If it was the gateway you should stop receiving data from other sensors too, right?



  • @AWI said in My Slim 2AA Battery Node:

    @rollercontainer Your sleep looks good. Did you remove this piece of code?

    // Activate internal pull-ups
    	digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
    	digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
    

    Take a look at this thread for a < 1 uA consumption...

    Hmm, I noticed, that I have to disable the internal pullups. But instead of removing the lines, I set them to LOW. I will test it without the lines and come back. Thank you @AWI.



  • Ok, just want to give you an update:

    I have 3 sensors running in the moment, initially I planned to run a lot more, but I still have problems with freezing of the sensors. The Sensors ran 2 months now until they were not coummunicating anymore, 1 is still working. I restarted 1 of the freezed sensors and it just came back up and works fine again, I leave the other one "freezed" just to see if it would come up again...

    It´s sad that they are not very reliable but I don´t get what makes them freeze after working quiet good for such a long time (they are reporting every 15 minutes 24/7 and whenever a window is opened/closed).

    I don´t think it´s a temp thing, also power should be no problem, batteries are still about 80 % loaded...



  • Maybe there is something like a counter (variable++) which causes a overflow after two month?



  • No, not really, but if you want to you can check my code:

    // Sensor Node Schlafzimmer mit HTU21D Temp/Hum Sensor, Fensterkontakte an Interrupt PINS Digital 5&6. Sleep Time 15 Minutwn, wake up wenn Fenster geöffnet/geschlossen wird.
    #define MY_RADIO_NRF24 //MySensor Library auf NRF24 Funkmodul einstellen, muss vor MySensor.h Initialisierung geschehen
    // Define Node ID
    #define MY_NODE_ID 1
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    //Batterysensor
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int oldBatteryPcnt = 0;
    #define CHILD_ID_BATT 7
    
    //Kontaktschalter
    //#include <Bounce2.h>
    #define CHILD1_ID 1 // Kontaktschalter 1
    #define CHILD2_ID 2 // Kontaktschalter 2
    #define BUTTON1_PIN  2  // Kontaktschalter 1
    #define BUTTON2_PIN  3  // Kontaktschalter 2
    int oldValueReed1=-1;
    int oldValueReed2=-1;
    
    //Tempsensor
    #include <SparkFunHTU21D.h>
    #include <Wire.h>
    #define CHILD_ID_HUM 3
    #define CHILD_ID_TEMP 4
    unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds)
    
    #include <MySensors.h>
    #include <SPI.h>
    
    //tempsensor
    HTU21D myHumidity;
    float lastTemp;
    float lastHum;
    //boolean metric = true; 
    
    //Messages
    //Battery
    MyMessage msgbatt(CHILD_ID_BATT,V_VOLTAGE);
    // Kontaktschalter
    MyMessage msgReed1(CHILD1_ID,V_TRIPPED); // Kontaktschalter 1
    MyMessage msgReed2(CHILD2_ID,V_TRIPPED); // Kontaktschalter 2
    //TempMessage
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    //Presentation; present sensors to gateway!
    void presentation(){
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Schlafzimmer Messstation", "2.0");
        
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(CHILD1_ID, S_DOOR); 
      present(CHILD2_ID, S_DOOR); 
        
      //Tempsensor
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP); 
      //metric = getConfig().isMetric;
    
      //Battery
      present(CHILD_ID_BATT,V_VOLTAGE);
    }
    
    //Setup
    void setup()  
    {  
      //Serial.begin(9600);
      Serial.println("Hello!");
      //Batterysensor
         // use the 1.1 V internal reference
    #if defined(__AVR_ATmega2560__)
       analogReference(INTERNAL1V1);
    #else
       analogReference(INTERNAL);
    #endif
    
    //Tempsensor
      Serial.println("Setting up TempSensor...");
      myHumidity.begin();
      Serial.println("...done!");
    
    // Setup Kontaktschalter 1
      pinMode(BUTTON1_PIN,INPUT);
        // Activate internal pull-up
      digitalWrite(BUTTON1_PIN,HIGH);
    // Setup Kontaktschalter 2
      pinMode(BUTTON2_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON2_PIN,HIGH);
    }
    
    //Starte den Loop
    void loop() 
    {
      //Batterysensor
      // get the battery Voltage
      delay(1000);
       int sensorValue = analogRead(BATTERY_SENSE_PIN);
       #ifdef DEBUG
       #endif
       
       // 1M, 470K divider across battery and using internal ADC ref of 1.1V
       // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
       // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
       // 3.44/1023 = Volts per bit = 0.003363075
       float batteryV  = sensorValue * 0.003363075;
       int batteryPcnt = sensorValue / 10;
    
       #ifdef DEBUG
       Serial.print("Battery Voltage: ");
       Serial.print(batteryV);
       Serial.println(" V");
    
       Serial.print("Battery percent: ");
       Serial.print(batteryPcnt);
       Serial.println(" %");
       #endif
    
       if (oldBatteryPcnt != batteryPcnt) {
         // Power up radio after sleep
         sendBatteryLevel(batteryPcnt);
         send(msgbatt.set(batteryPcnt));
         oldBatteryPcnt = batteryPcnt;
       }
       
      //Kontakstschalter 1
       // Short delay to allow buttons to properly settle
      wait(10);
      // Get the update value
      int valueReed1 = digitalRead(BUTTON1_PIN);
     
      if (valueReed1 != oldValueReed1) {
         // Send in the new value
         send(msgReed1.set(valueReed1==HIGH ? 1 : 0));
         Serial.println("Button 1 geschaltet");
         oldValueReed1 = valueReed1;
      }
      //Kontakstschalter 2
      // Get the update value
      int valueReed2 = digitalRead(BUTTON2_PIN);
     
      if (valueReed2 != oldValueReed2) {
         // Send in the new value
         send(msgReed2.set(valueReed2==HIGH ? 1 : 0));
         Serial.println("Button 2 geschaltet");
         oldValueReed2 = valueReed2;
      }
     
     //Tempsensor
    Serial.println("Starte Messung...");
      
        float temp = myHumidity.readTemperature();
    
      if (isnan(temp)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temp != lastTemp) {
        lastTemp = temp;
        send(msgTemp.set(temp, 1));
        Serial.print("T: ");
        Serial.println(temp);
      }
      
     float humd = myHumidity.readHumidity();
      if (isnan(humd)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humd != lastHum) {
          lastHum = humd;
          send(msgHum.set(humd, 1));
          Serial.print("H: ");
          Serial.println(humd);
      }
    
     Serial.println("Sleep...");
     sleep(BUTTON1_PIN - 2, CHANGE, BUTTON2_PIN - 2, CHANGE, SLEEP_TIME); //sleep a bit 
      
    } 
    
    


  • @AWI: I am down to 1,3 µA 👍

    my code:

    //#define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_NODE_ID 66
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    #include <MySensors.h>
    #include "Vcc.h"
    
    #define SKETCH_NAME "MySlim2aaBatteryNode"
    
    #define PRIMARY_CHILD_ID 3
    #define PRIMARY_BUTTON_PIN 3
    
    MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
    
    const float VccMin   = 1.7;           // Minimum expected Vcc level, in Volts.
    const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
    const float VccCorrection = 3.496 / 3.572;  // Measured Vcc by multimeter divided by reported Vcc
    
    const int32_t report_interval = 8640000; // 1day -> h * m * s * ms NOTICE: milliseconds, not microseconds!
    
    Vcc vcc(VccCorrection);
    
    #ifdef MY_DEBUG
    void before(){
        Serial.begin(9600);
    }
    #endif
    
    void setup()
    {
        pinMode(PRIMARY_BUTTON_PIN, INPUT);
    }
    
    void presentation()
    {
        sendSketchInfo(SKETCH_NAME, __DATE__);
        present(PRIMARY_CHILD_ID, S_DOOR, "Reed Contact");
    }
    
    void loop()
    {
        int32_t timestamp = millis();
    
        uint8_t reedState;
        static uint8_t lastReedState = 2;
        static int32_t lastBatteryReport = -report_interval; // for inital report
        sleep(5); // Short delay to allow buttons to properly settle
    
        reedState = digitalRead(PRIMARY_BUTTON_PIN);
    
        if ( (timestamp-lastBatteryReport) >= report_interval ) {
          uint8_t batteryPercent = (uint8_t)vcc.Read_Perc(VccMin, VccMax);
          sendBatteryLevel(batteryPercent);
          lastBatteryReport = timestamp;
        }
    
        if (reedState != lastReedState) {
            // Value has changed from last transmission, send the updated reedState
            send(msg.set(reedState==HIGH));
            lastReedState = reedState;
        }
    
        sleep(PRIMARY_BUTTON_PIN-2, CHANGE, 0);
    }
    
    

  • Hardware Contributor

    @siod
    Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

    What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..


  • Hero Member

    @Tim-Abels 👍 that is how you do it

    Be aware that the timer (millis()) is not running during sleep.


  • Hardware Contributor

    @Tim-Abels
    1.3uA is nice!
    A question about your sketch: Is millis() working because it's an interrupt-only sleep() or have I missed something else? As I recall it millis() stops working when using sleep().
    Edit: Haha. @AWI got it before me! 😄



  • @AWI one step forward, two steps back... Thanks for the hint.

    I guess, I should send battery percentage every 10 interrupts or so. Even if the contact doesn't trigger for a while, I can force it by showing my neighbours my ocd on doors ^^ (knock, knock, knock - Penny!)

    What do you think?



  • Just noticed, that I use another login at home. So, the Tim-Abels is the rollercontainer... Sorry for that.


  • Hero Member

    @rollercontainer alias @Tim-Abels 😉 Sounds good, although with 1.3uA the battery won't show much variation..

    This is a similar on running on a coin cell (not calibrated). The voltage drop is caused mainly by the bad radio connection (many retries for sending > 10 mA)

    0_1487319381911_upload-02a06ce9-126d-49f2-bbcb-dd01c3cea3d4



  • Maybe its better to measure the voltage every 10 or 100 loops and only send one custom message/alert when its dropped below a threshold. I am using the MQTTClientGateway and Node-Red. In case of a battery-low message, node-red could send me an email with the node name. I will give it a try...

    From https://www.mysensors.org/download/serial_api_20:

    V_TEXT          47 	Text message to display on LCD or controller device 	S_INFO
    V_CUSTOM 	48 	Custom messages used for controller/inter node specific commands, preferably using S_CUSTOM device type. 	S_CUSTOM```


  • Did you considered a tiny solar cell like enocean does?
    https://www.enocean.com/en/enocean_modules/stm-320/
    That would be perfect...



  • searched a bit and found that @ceech already made a harvester with a coin cell.

    http://www.ebay.de/itm/BQ25570-thermal-solar-energy-harvester-/332071662285

    still too big and too expensive in comparison with dozens of alkaline batteries which will run for years, but that is the way to go sometime.



  • @m26872 said in My Slim 2AA Battery Node:

    @siod
    Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

    What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

    @m26872
    Gateway seems to work fine as the 3rd and still working sensor is still communicating. Also the freezed sensors start communicating after I restarted the sensor, not the GW. So I don´t see a problem with the GW.
    "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?
    I have not attached a heartbeat LED yet, but that´s sth. I could do as a next step...
    The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...
    You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

    Thanks so far!!


  • Hardware Contributor

    @siod said in My Slim 2AA Battery Node:

    "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?

    I meant the https://www.mysensors.org/controller/sniffer, but I think it's easier to equip sensors with Radio Traffic LEDs and/or your own heartbeat/error LEDs.

    The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...

    I suggest you start with deleting or replacing this delay. It could be it.

    You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

    I think you had pull-up inputs. Then it's just to replace the CHANGE with LOW in your call to sleep().

    Thanks so far!!

    My personal troubleshooting method in cases like these (and too many others) is just exhaustive use of the good old substitution method. Hw, Sw, entire systems or whatever you can do. 😬



  • deleted - it´s working now, I must have made a mistake... 😊

    edit:

    one strange thing: The sensor should report every 15 minutes (900000 milisecs), but it reports only every 18 minutes. Don´t know why.



  • Hello everybody,

    I´m struggeling with getting the https://forum.mysensors.org/topic/2715/slim-node-as-a-mini-2aa-battery-pir-motion-sensor
    to work.
    The node registers with the GW, but doesnt submit the tripped reading.
    Not even a permanent on or something. Just nothing. So i dont know how to troubleshoot here.
    The PIR HC-SR505 is functional. I tested it with a testscript on a UNO.
    And the 2AA Slimnode is functional as well. When using the node as a binary switch it works perfectly fine,
    Just the combination 2AA Slimnode and HC-SR505 doesnt work.

    Anybody has an idea ?

    Thanks in advance Komaandy


  • Mod

    Did you check the serial output if you get debug messages?


  • Hero Member

    @Komaandy please don't double post. Please continue in the other thread



  • Does anybody has a idea why my nodes keep freezing ?
    I build like 5 identical nodes with a PIR and after working fine for a couple of hours at least half of them freeze.
    There is one particular node that is working for 4 days now straight, but all the others are frozen meanwhile.
    I have no idea where to start troubleshooting, as they are all the same ( capacitory, resistors,radios,Atmega328p,batteries,solder,radio,sketch)
    and are all basically within the same radius placed around the gateway. I have other "not battery Slim Nodes" and they never freeze, though running the same sketch.

    Please i need some tips

    Regards

    Komaandy


  • Hardware Contributor

    @Komaandy - did you try the hardware without the PIR?



  • Do you mean running the node without the PIR ?
    I thought about, I guess i will test it.
    You think the PIR freezes the node ?


  • Hardware Contributor

    @Komaandy - Yes and Yes 🙂
    Its a good way to debug, remove not crucial stuff to see if it works... one by one and you will figure it out.
    The PIR (depending on which one and what kind of power you are using) might be the problem but hard to say without knowing your setup.


  • Hardware Contributor

    @AWI said in My Slim 2AA Battery Node:

    @Komaandy please don't double post. Please continue in the other thread

    @Komaandy and @sundberg84 Once again; Please continue in the other thread! Especially since @Komaandy now confirmed that it is this far NOT a generic Slim Node issue. Also, I haven't got any feedback on my reply there, but I assume it didn't work?



  • Hi @Komaandy ,

    unfortunately I must report that I made the same expiriences you made. I am running 5 "My SLim 2AA Battery Node" Sensors from which only 2 really work. The others keep freezing after an hour, a day, are sometimes after a few days. I have still no idea why this is happening, but because of this I stopped building more of the "My SLim 2AA Battery Node" sensors, which is very sad, because it´s an ingeniuous design.

    I am using MQTT and therefore I installed NRF24L01 modules. Some of them are really weak, so I thought that´s the problem: The node does not freeze, it´s just the NRF24L01 that is not sending any info anymore. So I attached a LED to my node to see if it is still alive. Whenever I opened a window the LED must lid. So when I did not got any info from the node I checked if the node is still operational by opening a window and there I noticed when the LED did not lid, that the node was completely frozen. So It was not a wireless connection problem, but the NRF24L01 of course could still be the problem.
    A lot of my investigastions was about figuring out what is happening when entering the sleep mode, because I thought (and still believe) the node is just not waking up from sleep anymore. Unluckily I still did not find a solution.
    Anywhere you said that the none battery driven nodes are working flawlessly, that´s another point I was thinking about. I have one MQTT Arduino Nano device in the basement which is directly powered over USB and I never had problems with it, also the MQTT / NRF24L01 range is awesome.
    But I have no oscillator or anything to check if it a power problem with the "My Slim 2AA Battery Node".
    Maybe you´ll find a solution for your problems which could help me, too. I´m looking forward hearing from you.


  • Hardware Contributor

    @siod Thanks for your report. Could you please share some more info. Hw/sw versions, nRF-batches, sensors, configs/settings, sketches etc. @Komaandy could only confirm issues with a PIR eqiupped node, but you have a door-switch so I guess it's a potential generic problem then. Let's hope for other reports as to help us narrow down the search.

    I have not yet migrated to MySensors 2.x 😳 , but it's hopefully coming soon. My Slim Nodes from the start of this thread (~ 10 pcs) are still in flawless production.


  • Hardware Contributor

    @m26872 - I made myself a slim node with a light sensor and a uv-sensor last weekend. Its running latest dev branch and has been working flawless atleast 1 week now.



  • @m26872 First of all: I already got so much help and I am very grateful for that, awesome community!

    I don´t think I will ever find the problem with those sensors and because of the lack of time I have (familiy, work...) I think looking for the problem would take longer than just build a new sensor. And that´s what I will do next: I will just build another node, one step after the other and so I can validate if it maybe is a hardware problem or a code problem. BTW my whole sketch is just a few posts above this one...

    So I will come back after I started over...



  • @m26872

    Hi there,

    im still into troubleshooting, and what i did last was create a "mock up temperatursensor slim node " with this sketch
    , so its really only the node and batteries. But it still freezes 😞
    Hardware i use is :

    -Atmega328p 1Mhz bootloader. // Burnt the bootloader with one Arduino UNO as master and another Arduino UNO on which I replaced the Atmega328p as slave // Arduino as ISP // with the latest Arduino IDE (1.8.2)

    • after burning the bootloader on the bare ATMEGA´s i assemble them on the node and transfer the sketch via FTDI232

    Furthermore i use
    -generic Capacitors and restistors ( specs from your BOM)

    • Kuman nRF24L01 batches ( bought like 30 in a bulk once, but other "nonslimnodes" are working)
      -fresh batteries

    Any help is very aprreciated 🙂 🙂

    /*
    * MockMySensors
    *
    * This skecth is intended to crate fake sensors which register and respond to the controller
    * ***
    * Barduino 2015, GizMoCuz 2015
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 123
    
    #include <MySensors.h>
    
    #define RADIO_ERROR_LED_PIN 4  // Error led pin
    #define RADIO_RX_LED_PIN    6  // Receive led pin
    #define RADIO_TX_LED_PIN    13  // the PCB, on board LED
    
    // Wait times
    #define LONG_WAIT 500
    #define SHORT_WAIT 50
    
    #define SKETCH_NAME "MockMySensors "
    #define SKETCH_VERSION "v0.5"
    
    // Define Sensors ids
    /*      S_DOOR, S_MOTION, S_SMOKE, S_LIGHT, S_DIMMER, S_COVER, S_TEMP, S_HUM, S_BARO, S_WIND,
       S_RAIN, S_UV, S_WEIGHT, S_POWER, S_HEATER, S_DISTANCE, S_LIGHT_LEVEL, S_ARDUINO_NODE,
       S_ARDUINO_REPEATER_NODE, S_LOCK, S_IR, S_WATER, S_AIR_QUALITY, S_CUSTOM, S_DUST,
       S_SCENE_CONTROLLER
    */
    
    ////#define ID_S_ARDUINO_NODE            //auto defined in initialization
    ////#define ID_S_ARDUINO_REPEATER_NODE   //auto defined in initialization
    
    
    // Some of these ID's have not been updated for v1.5.  Uncommenting too many of them
    // will make the sketch too large for a pro mini's memory so it's probably best to try
    // one at a time.
    
    //#define ID_S_ARMED             0  // dummy to controll armed stated for several sensors
    //#define ID_S_DOOR              1
    //#define ID_S_MOTION            2
    //#define ID_S_SMOKE             3
    //#define ID_S_LIGHT             4
    //#define ID_S_DIMMER            5
    //#define ID_S_COVER             6
    #define ID_S_TEMP              7
    //#define ID_S_HUM               8
    //#define ID_S_BARO              9
    //#define ID_S_WIND              10
    //#define ID_S_RAIN              11
    //#define ID_S_UV                12
    //#define ID_S_WEIGHT            13
    //#define ID_S_POWER             14
    //#define ID_S_HEATER            15
    //#define ID_S_DISTANCE          16
    //#define ID_S_LIGHT_LEVEL       17
    //#define ID_S_LOCK              18
    //#define ID_S_IR                19
    //#define ID_S_WATER             20
    //#define ID_S_AIR_QUALITY       21
    //#define ID_S_DUST              22
    //#define ID_S_SCENE_CONTROLLER  23
    //// Lib 1.5 sensors
    //#define ID_S_RGB_LIGHT         24
    //#define ID_S_RGBW_LIGHT        25
    //#define ID_S_COLOR_SENSOR      26
    //#define ID_S_HVAC              27
    //#define ID_S_MULTIMETER        28
    //#define ID_S_SPRINKLER         29
    //#define ID_S_WATER_LEAK        30
    //#define ID_S_SOUND             31
    //#define ID_S_VIBRATION         32
    //#define ID_S_MOISTURE          33
    //
    //#define ID_S_CUSTOM            99
    
    
    
    // Global Vars
    unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
    bool metric = true;
    long randNumber;
    
    
    //Instanciate Messages objects
    
    #ifdef ID_S_ARMED
    bool isArmed;
    #endif
    
    #ifdef ID_S_DOOR // V_TRIPPED, V_ARMED
    MyMessage msg_S_DOOR_T(ID_S_DOOR,V_TRIPPED);
    MyMessage msg_S_DOOR_A(ID_S_DOOR,V_ARMED);
    #endif
    
    #ifdef ID_S_MOTION // V_TRIPPED, V_ARMED
    MyMessage msg_S_MOTION_A(ID_S_MOTION,V_ARMED);
    MyMessage msg_S_MOTION_T(ID_S_MOTION,V_TRIPPED);
    #endif
    
    #ifdef ID_S_SMOKE  // V_TRIPPED, V_ARMED
    MyMessage msg_S_SMOKE_T(ID_S_SMOKE,V_TRIPPED);
    MyMessage msg_S_SMOKE_A(ID_S_SMOKE,V_ARMED);
    #endif
    
    #ifdef ID_S_LIGHT
    MyMessage msg_S_LIGHT(ID_S_LIGHT,V_LIGHT);
    bool isLightOn=0;
    #endif
    
    #ifdef ID_S_DIMMER
    MyMessage msg_S_DIMMER(ID_S_DIMMER,V_DIMMER);
    int dimmerVal=100;
    #endif
    
    #ifdef ID_S_COVER
    MyMessage msg_S_COVER_U(ID_S_COVER,V_UP);
    MyMessage msg_S_COVER_D(ID_S_COVER,V_DOWN);
    MyMessage msg_S_COVER_S(ID_S_COVER,V_STOP);
    MyMessage msg_S_COVER_V(ID_S_COVER,V_VAR1);
    int coverState=0; //0=Stop; 1=up; -1=down
    #endif
    
    #ifdef ID_S_TEMP
    MyMessage msg_S_TEMP(ID_S_TEMP,V_TEMP);
    #endif
    
    #ifdef ID_S_HUM
    MyMessage msg_S_HUM(ID_S_HUM,V_HUM);
    #endif
    
    #ifdef ID_S_BARO
    MyMessage msg_S_BARO_P(ID_S_BARO,V_PRESSURE);
    MyMessage msg_S_BARO_F(ID_S_BARO,V_FORECAST);
    #endif
    
    #ifdef ID_S_WIND
    MyMessage msg_S_WIND_S(ID_S_WIND,V_WIND);
    MyMessage msg_S_WIND_G(ID_S_WIND,V_GUST);
    MyMessage msg_S_WIND_D(ID_S_WIND,V_DIRECTION);
    #endif
    
    #ifdef ID_S_RAIN
    MyMessage msg_S_RAIN_A(ID_S_RAIN,V_RAIN);
    MyMessage msg_S_RAIN_R(ID_S_RAIN,V_RAINRATE);
    #endif
    
    #ifdef ID_S_UV
    MyMessage msg_S_UV(ID_S_UV,V_UV);
    #endif
    
    #ifdef ID_S_WEIGHT
    MyMessage msg_S_WEIGHT(ID_S_WEIGHT,V_WEIGHT);
    #endif
    
    #ifdef ID_S_POWER
    MyMessage msg_S_POWER_W(ID_S_POWER,V_WATT);
    MyMessage msg_S_POWER_K(ID_S_POWER,V_KWH);
    #endif
    
    
    #ifdef ID_S_HEATER
    
    //////// REVIEW IMPLEMENTATION ////////////
    
    MyMessage msg_S_HEATER_SET_POINT(ID_S_HEATER,
                                    V_HVAC_SETPOINT_HEAT);  // HVAC/Heater setpoint (Integer between 0-100). S_HEATER, S_HVAC
    MyMessage msg_S_HEATER_FLOW_STATE(ID_S_HEATER,
                                     V_HVAC_FLOW_STATE);     // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver" // S_HVAC, S_HEATER
    
    //MyMessage msg_S_HEATER_STATUS(ID_S_HEATER,V_STATUS);
    //MyMessage msg_S_HEATER_TEMP(ID_S_HEATER,V_TEMP);
    
    float heater_setpoint=21.5;
    String heater_flow_state="Off";
    
    //  float heater_temp=23.5;
    //  bool heater_status=false;
    
    
    // V_TEMP                // Temperature
    // V_STATUS              // Binary status. 0=off 1=on
    // V_HVAC_FLOW_STATE     // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver"
    // V_HVAC_SPEED          // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
    // V_HVAC_SETPOINT_HEAT  // HVAC/Heater setpoint
    #endif
    
    #ifdef ID_S_DISTANCE
    MyMessage msg_S_DISTANCE(ID_S_DISTANCE,V_DISTANCE);
    #endif
    
    #ifdef ID_S_LIGHT_LEVEL
    MyMessage msg_S_LIGHT_LEVEL(ID_S_LIGHT_LEVEL,V_LIGHT_LEVEL);
    #endif
    
    #ifdef ID_S_LOCK
    MyMessage msg_S_LOCK(ID_S_LOCK,V_LOCK_STATUS);
    bool isLocked = 0;
    #endif
    
    #ifdef ID_S_IR
    MyMessage msg_S_IR_S(ID_S_IR,V_IR_SEND);
    MyMessage msg_S_IR_R(ID_S_IR,V_IR_RECEIVE);
    long irVal = 0;
    #endif
    
    #ifdef ID_S_WATER
    MyMessage msg_S_WATER_F(ID_S_WATER,V_FLOW);
    MyMessage msg_S_WATER_V(ID_S_WATER,V_VOLUME);
    #endif
    
    #ifdef ID_S_AIR_QUALITY
    MyMessage msg_S_AIR_QUALITY(ID_S_AIR_QUALITY,V_LEVEL);
    #endif
    
    #ifdef ID_S_DUST
    MyMessage msg_S_DUST(ID_S_DUST,V_LEVEL);
    #endif
    
    #ifdef ID_S_SCENE_CONTROLLER
    MyMessage msg_S_SCENE_CONTROLLER_ON(ID_S_SCENE_CONTROLLER,V_SCENE_ON);
    MyMessage msg_S_SCENE_CONTROLLER_OF(ID_S_SCENE_CONTROLLER,V_SCENE_OFF);
    // not sure if scene controller sends int or chars
    // betting on ints as Touch Display Scen by Hek // compiler warnings
    char *scenes[] = {
       (char *)"Good Morning",
       (char *)"Clean Up!",
       (char *)"All Lights Off",
       (char *)"Music On/Off"
    };
    
    int sceneVal=0;
    int sceneValPrevious=0;
    
    #endif
    
    #ifdef ID_S_RGB_LIGHT
    MyMessage msg_S_RGB_LIGHT_V_RGB(ID_S_RGB_LIGHT,V_RGB);
    MyMessage msg_S_RGB_LIGHT_V_WATT(ID_S_RGB_LIGHT,V_WATT);
    String rgbState="000000";
    //RGB light V_RGB, V_WATT
    //RGB value transmitted as ASCII hex string (I.e "ff0000" for red)
    #endif
    
    #ifdef ID_S_RGBW_LIGHT
    MyMessage msg_S_RGBW_LIGHT_V_RGBW(ID_S_RGBW_LIGHT,V_RGBW);
    MyMessage msg_S_RGBW_LIGHT_V_WATT(ID_S_RGBW_LIGHT,V_WATT);
    String rgbwState="00000000";
    //RGBW light (with separate white component)	V_RGBW, V_WATT
    //RGBW value transmitted as ASCII hex string (I.e "ff0000ff" for red + full white)	S_RGBW_LIGHT
    #endif
    
    #ifdef ID_S_COLOR_SENSOR
    MyMessage msg_S_COLOR_SENSOR_V_RGB(ID_S_COLOR_SENSOR,V_RGB);
    //Color sensor	V_RGB
    //RGB value transmitted as ASCII hex string (I.e "ff0000" for red)	S_RGB_LIGHT, S_COLOR_SENSOR
    #endif
    
    #ifdef ID_S_HVAC
    MyMessage msg_S_HVAC_V_HVAC_SETPOINT_HEAT(ID_S_HVAC,V_HVAC_SETPOINT_HEAT);
    MyMessage msg_S_HVAC_V_HVAC_SETPOINT_COOL(ID_S_HVAC,V_HVAC_SETPOINT_COOL);
    MyMessage msg_S_HVAC_V_HVAC_FLOW_STATET(ID_S_HVAC,V_HVAC_FLOW_STATE);
    MyMessage msg_S_HVAC_V_HVAC_FLOW_MODE(ID_S_HVAC,V_HVAC_FLOW_MODE);
    MyMessage msg_S_HVAC_V_HVAC_SPEED(ID_S_HVAC,V_HVAC_SPEED);
    
    float hvac_SetPointHeat = 16.5;
    float hvac_SetPointCool = 25.5;
    String hvac_FlowState   = "AutoChangeOver";
    String hvac_FlowMode    = "Auto";
    String hvac_Speed       = "Normal";
    
    //Thermostat/HVAC device
    //V_HVAC_SETPOINT_HEAT,  // HVAC/Heater setpoint
    //V_HVAC_SETPOINT_COOL,  // HVAC cold setpoint
    //V_HVAC_FLOW_STATE,     // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver"
    //V_HVAC_FLOW_MODE,      // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn")
    //V_HVAC_SPEED           // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
    
    // NOT IMPLEMENTED YET
    //V_TEMP                 // Temperature
    //V_STATUS               // Binary status. 0=off 1=on
    #endif
    
    #ifdef ID_S_MULTIMETER
    MyMessage msg_S_MULTIMETER_V_IMPEDANCE(ID_S_MULTIMETER,V_IMPEDANCE);
    MyMessage msg_S_MULTIMETER_V_VOLTAGE(ID_S_MULTIMETER,V_VOLTAGE);
    MyMessage msg_S_MULTIMETER_V_CURRENT(ID_S_MULTIMETER,V_CURRENT);
    
    // Multimeter device	V_VOLTAGE, V_CURRENT, V_IMPEDANCE
    // V_IMPEDANCE	14	Impedance value
    // V_VOLTAGE	38	Voltage level
    // V_CURRENT	39	Current level
    #endif
    
    #ifdef ID_S_SPRINKLER
    // S_SPRINKLER	31	Sprinkler device	V_STATUS (turn on/off), V_TRIPPED (if fire detecting device)
    // V_STATUS	2	Binary status. 0=off 1=on
    // V_ARMED	15	Armed status of a security sensor. 1=Armed, 0=Bypassed
    // V_TRIPPED	16	Tripped status of a security sensor. 1=Tripped, 0=Untripped
    #endif
    
    #ifdef ID_S_WATER_LEAK
    #endif
    #ifdef ID_S_SOUND
    #endif
    #ifdef ID_S_VIBRATION
    #endif
    #ifdef ID_S_MOISTURE
    #endif
    
    #ifdef ID_S_MOISTURE
    MyMessage msg_S_MOISTURE(ID_S_MOISTURE,V_LEVEL);
    #endif
    
    #ifdef ID_S_CUSTOM
    MyMessage msg_S_CUSTOM_1(ID_S_CUSTOM,V_VAR1);
    MyMessage msg_S_CUSTOM_2(ID_S_CUSTOM,V_VAR2);
    MyMessage msg_S_CUSTOM_3(ID_S_CUSTOM,V_VAR3);
    MyMessage msg_S_CUSTOM_4(ID_S_CUSTOM,V_VAR4);
    MyMessage msg_S_CUSTOM_5(ID_S_CUSTOM,V_VAR5);
    #endif
    
    
    
    
    void setup()
    {
       // Random SEED
       randomSeed(analogRead(0));
    
       wait(LONG_WAIT);
       Serial.println("GW Started");
    }
    
    void presentation()
    {
       // Send the Sketch Version Information to the Gateway
       Serial.print("Send Sketch Info: ");
       sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
       Serial.print(SKETCH_NAME);
       Serial.println(SKETCH_VERSION);
       wait(LONG_WAIT);
    
       // Get controller configuration
       Serial.print("Get Config: ");
       metric = getControllerConfig().isMetric;
       Serial.println(metric ? "Metric":"Imperial");
       wait(LONG_WAIT);
    
       // Init Armed
    #ifdef ID_S_ARMED
       isArmed = true;
    #endif
    
       // Register all sensors to gw (they will be created as child devices)
       Serial.println("Presenting Nodes");
       Serial.println("________________");
    
    #ifdef ID_S_DOOR
       Serial.println("  S_DOOR");
       present(ID_S_DOOR,S_DOOR,"Outside Door");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_MOTION
       Serial.println("  S_MOTION");
       present(ID_S_MOTION,S_MOTION,"Outside Motion");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_SMOKE
       Serial.println("  S_SMOKE");
       present(ID_S_SMOKE,S_SMOKE,"Kitchen Smoke");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_LIGHT
       Serial.println("  S_LIGHT");
       present(ID_S_LIGHT,S_LIGHT,"Hall Light");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_DIMMER
       Serial.println("  S_DIMMER");
       present(ID_S_DIMMER,S_DIMMER,"Living room dimmer");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_COVER
       Serial.println("  S_COVER");
       present(ID_S_COVER,S_COVER,"Window cover");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_TEMP
       Serial.println("  S_TEMP");
       present(ID_S_TEMP,S_TEMP,"House Temperarue");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_HUM
       Serial.println("  S_HUM");
       present(ID_S_HUM,S_HUM,"Current Humidity");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_BARO
       Serial.println("  S_BARO");
       present(ID_S_BARO,S_BARO," Air pressure");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_WIND
       Serial.println("  S_WIND");
       present(ID_S_WIND,S_WIND,"Wind Station");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_RAIN
       Serial.println("  S_RAIN");
       present(ID_S_RAIN,S_RAIN,"Rain Station");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_UV
       Serial.println("  S_UV");
       present(ID_S_UV,S_UV,"Ultra Violet");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_WEIGHT
       Serial.println("  S_WEIGHT");
       present(ID_S_WEIGHT,S_WEIGHT,"Outdoor Scale");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_POWER
       Serial.println("  S_POWER");
       present(ID_S_POWER,S_POWER,"Power Metric");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_HEATER
       Serial.println("  S_HEATER");
       present(ID_S_HEATER,S_HEATER,"Garage Heater");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_DISTANCE
       Serial.println("  S_DISTANCE");
       present(ID_S_DISTANCE,S_DISTANCE,"Distance Measure");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_LIGHT_LEVEL
       Serial.println("  S_LIGHT_LEVEL");
       present(ID_S_LIGHT_LEVEL,S_LIGHT_LEVEL,"Outside Light Level");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_LOCK
       Serial.println("  S_LOCK");
       present(ID_S_LOCK,S_LOCK,"Front Door Lock");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_IR
       Serial.println("  S_IR");
       present(ID_S_IR,S_IR,"Univeral Command");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_WATER
       Serial.println("  S_WATER");
       present(ID_S_WATER,S_WATER,"Water Level");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_AIR_QUALITY
       Serial.println("  S_AIR_QUALITY");
       present(ID_S_AIR_QUALITY,S_AIR_QUALITY,"Air Station");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_DUST
       Serial.println("  S_DUST");
       present(ID_S_DUST,S_DUST,"Dust Level");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_SCENE_CONTROLLER
       Serial.println("  S_SCENE_CONTROLLER");
       present(ID_S_SCENE_CONTROLLER,S_SCENE_CONTROLLER,"Scene Controller");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_RGB_LIGHT
       Serial.println("  RGB_LIGHT");
       present(ID_S_RGB_LIGHT,S_RGB_LIGHT,"Mood Light");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_RGBW_LIGHT
       Serial.println("  RGBW_LIGHT");
       present(ID_S_RGBW_LIGHT,S_RGBW_LIGHT,"Mood Light 2");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_COLOR_SENSOR
       Serial.println("  COLOR_SENSOR");
       present(ID_S_COLOR_SENSOR,S_COLOR_SENSOR,"Hall Painting");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_HVAC
       Serial.println("  HVAC");
       present(ID_S_HVAC,S_HVAC,"HVAC");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_MULTIMETER
       Serial.println("  MULTIMETER");
       present(ID_S_MULTIMETER,S_MULTIMETER,"Electric Staion");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_SPRINKLER
    #endif
    #ifdef ID_S_WATER_LEAK
    #endif
    #ifdef ID_S_SOUND
    #endif
    #ifdef ID_S_VIBRATION
    #endif
    #ifdef ID_S_MOISTURE
    #endif
    
    #ifdef ID_S_MOISTURE
       Serial.println("  S_MOISTURE");
       present(ID_S_MOISTURE,S_MOISTURE,"Basement Sensor");
       wait(SHORT_WAIT);
    #endif
    
    #ifdef ID_S_CUSTOM
       Serial.println("  S_CUSTOM");
       present(ID_S_CUSTOM,S_CUSTOM,"Other Stuff");
       wait(SHORT_WAIT);
    #endif
    
    
    
       Serial.println("________________");
    
    }
    
    void loop()
    {
       Serial.println("");
       Serial.println("");
       Serial.println("");
       Serial.println("#########################");
       randNumber=random(0,101);
    
       Serial.print("RandomNumber:");
       Serial.println(randNumber);
       // Send fake battery level
       Serial.println("Send Battery Level");
       sendBatteryLevel(randNumber);
       wait(LONG_WAIT);
    
       // Request time
       Serial.println("Request Time");
       requestTime();
       wait(LONG_WAIT);
    
       //Read Sensors
    #ifdef ID_S_DOOR
       door();
    #endif
    
    #ifdef ID_S_MOTION
       motion();
    #endif
    
    #ifdef ID_S_SMOKE
       smoke();
    #endif
    
    #ifdef ID_S_LIGHT
       light();
    #endif
    
    #ifdef ID_S_DIMMER
       dimmer();
    #endif
    
    #ifdef ID_S_COVER
       cover();
    #endif
    
    #ifdef ID_S_TEMP
       temp();
    #endif
    
    #ifdef ID_S_HUM
       hum();
    #endif
    
    #ifdef ID_S_BARO
       baro();
    #endif
    
    #ifdef ID_S_WIND
       wind();
    #endif
    
    #ifdef ID_S_RAIN
       rain();
    #endif
    
    #ifdef ID_S_UV
       uv();
    #endif
    
    #ifdef ID_S_WEIGHT
       weight();
    #endif
    
    #ifdef ID_S_POWER
       power();
    #endif
    
    #ifdef ID_S_HEATER
       heater();
    #endif
    
    #ifdef ID_S_DISTANCE
       distance();
    #endif
    
    #ifdef ID_S_LIGHT_LEVEL
       light_level();
    #endif
    
    #ifdef ID_S_LOCK
       lock();
    #endif
    
    #ifdef ID_S_IR
       ir();
    #endif
    
    #ifdef ID_S_WATER
       water();
    #endif
    
    #ifdef ID_S_AIR_QUALITY
       air();
    #endif
    
    #ifdef ID_S_DUST
       dust();
    #endif
    
    #ifdef ID_S_SCENE_CONTROLLER
       scene();
    #endif
    
    #ifdef ID_S_RGB_LIGHT
       rgbLight();
    #endif
    
    #ifdef ID_S_RGBW_LIGHT
       rgbwLight();
    #endif
    
    #ifdef ID_S_COLOR_SENSOR
       color();
    #endif
    
    #ifdef ID_S_HVAC
       hvac();
    #endif
    
    #ifdef ID_S_MULTIMETER
       multimeter();
    #endif
    
    #ifdef ID_S_SPRINKLER
    #endif
    #ifdef ID_S_WATER_LEAK
    #endif
    #ifdef ID_S_SOUND
    #endif
    #ifdef ID_S_VIBRATION
    #endif
    #ifdef ID_S_MOISTURE
    #endif
    
    #ifdef ID_S_MOISTURE
       moisture();
    #endif
    
    #ifdef ID_S_CUSTOM
       custom();
    #endif
    
       sendBatteryLevel(randNumber);
       wait(SHORT_WAIT);
       Serial.println("#########################");
       wait(SLEEP_TIME); //sleep a bit
    }
    
    // This is called when a new time value was received
    void receiveTime(unsigned long controllerTime)
    {
    
       Serial.print("Time value received: ");
       Serial.println(controllerTime);
    
    }
    
    //void door(){}
    
    #ifdef ID_S_DOOR
    void door()
    {
    
       Serial.print("Door is: " );
    
       if (randNumber <= 50) {
       	Serial.println("Open");
       	send(msg_S_DOOR_T.set((int16_t)1));
       } else {
       	Serial.println("Closed");
       	send(msg_S_DOOR_T.set((int16_t)0));
       }
    #ifdef ID_S_ARMED
       Serial.print("System is: " );
       Serial.println((isArmed ? "Armed":"Disarmed"));
       send(msg_S_DOOR_A.set(isArmed));
    #endif
    }
    #endif
    
    #ifdef ID_S_MOTION
    void motion()
    {
    
       Serial.print("Motion is: " );
    
       if (randNumber <= 50) {
       	Serial.println("Active");
       	send(msg_S_MOTION_T.set(1));
       } else {
       	Serial.println("Quiet");
       	send(msg_S_MOTION_T.set(0));
       }
    
    #ifdef ID_S_ARMED
       Serial.print("System is: " );
       Serial.println((isArmed ? "Armed":"Disarmed"));
       send(msg_S_MOTION_A.set(isArmed));
    #endif
    }
    #endif
    
    #ifdef ID_S_SMOKE
    void smoke()
    {
    
       Serial.print("Smoke is: " );
    
       if (randNumber <= 50) {
       	Serial.println("Active");
       	send(msg_S_SMOKE_T.set(1));
       } else {
       	Serial.println("Quiet");
       	send(msg_S_SMOKE_T.set(0));
       }
    
    #ifdef ID_S_ARMED
       Serial.print("System is: " );
       Serial.println((isArmed ? "Armed":"Disarmed"));
       send(msg_S_SMOKE_A.set(isArmed));
    #endif
    
    }
    #endif
    
    #ifdef ID_S_LIGHT
    void light()
    {
    
       Serial.print("Light is: " );
       Serial.println((isLightOn ? "On":"Off"));
    
       send(msg_S_LIGHT.set(isLightOn));
    
    }
    #endif
    
    #ifdef ID_S_DIMMER
    void dimmer()
    {
    
       Serial.print("Dimmer is set to: " );
       Serial.println(dimmerVal);
    
       send(msg_S_DIMMER.set(dimmerVal));
    
    }
    #endif
    
    #ifdef ID_S_COVER
    void cover()
    {
    
       Serial.print("Cover is : " );
    
       if (coverState == 1) {
       	Serial.println("Opening");
       	send(msg_S_COVER_U.set(1));
       } else if (coverState == -1) {
       	Serial.println("Closing");
       	send(msg_S_COVER_D.set(0));
       } else {
       	Serial.println("Idle");
       	send(msg_S_COVER_S.set(-1));
       }
       send(msg_S_COVER_V.set(coverState));
    }
    #endif
    
    #ifdef ID_S_TEMP
    void temp()
    {
    
       Serial.print("Temperature is: " );
       Serial.println(map(randNumber,1,100,0,45));
    
       send(msg_S_TEMP.set(map(randNumber,1,100,0,45)));
    
    }
    #endif
    
    #ifdef ID_S_HUM
    void hum()
    {
    
       Serial.print("Humitidty is: " );
       Serial.println(randNumber);
    
       send(msg_S_HUM.set(randNumber));
    
    }
    #endif
    
    #ifdef ID_S_BARO
    void baro()
    {
    
       const char *weather[] = {"stable","sunny","cloudy","unstable","thunderstorm","unknown"};
       long pressure = map(randNumber,1,100,870,1086);// hPa?
       int forecast = map(randNumber,1,100,0,5);
    
       Serial.print("Atmosferic Pressure is: " );
       Serial.println(pressure);
       send(msg_S_BARO_P.set(pressure));
    
       Serial.print("Weather forecast: " );
       Serial.println(weather[forecast]);
       send(msg_S_BARO_F.set(weather[forecast]));
    
    }
    #endif
    
    #ifdef ID_S_WIND
    void wind()
    {
    
       Serial.print("Wind Speed is: " );
       Serial.println(randNumber);
       send(msg_S_WIND_S.set(randNumber));
    
       Serial.print("Wind Gust is: " );
       Serial.println(randNumber+10);
       send(msg_S_WIND_G.set(randNumber+10));
    
       Serial.print("Wind Direction is: " );
       Serial.println(map(randNumber,1,100,0,360));
       send(msg_S_WIND_D.set(map(randNumber,1,100,0,360)));
    
    }
    #endif
    
    #ifdef ID_S_RAIN
    void rain()
    {
    
       Serial.print("Rain ammount  is: " );
       Serial.println(randNumber);
    
       send(msg_S_RAIN_A.set(randNumber));
    
       Serial.print("Rain rate  is: " );
       Serial.println(randNumber/60);
    
       send(msg_S_RAIN_R.set(randNumber/60,1));
    
    }
    #endif
    
    #ifdef ID_S_UV
    void uv()
    {
    
       Serial.print("Ultra Violet level is: " );
       Serial.println(map(randNumber,1,100,0,15));
    
       send(msg_S_UV.set(map(randNumber,1,100,0,15)));
    
    }
    #endif
    
    #ifdef ID_S_WEIGHT
    void weight()
    {
    
       Serial.print("Weight is: " );
       Serial.println(map(randNumber,1,100,0,150));
    
       send(msg_S_WEIGHT.set(map(randNumber,1,100,0,150)));
    
    }
    #endif
    
    #ifdef ID_S_POWER
    void power()
    {
    
       Serial.print("Watt is: " );
       Serial.println(map(randNumber,1,100,0,150));
       send(msg_S_POWER_W.set(map(randNumber,1,100,0,150)));
    
       Serial.print("KWH is: " );
       Serial.println(map(randNumber,1,100,0,150));
       send(msg_S_POWER_K.set(map(randNumber,1,100,0,150)));
    
    }
    #endif
    
    #ifdef ID_S_HEATER
    void heater()
    {
       //  float heater_setpoint=21.5;
       //  float heater_temp=23.5;
       //  bool heater_status=false;
       //  String heatState="Off";
    
       Serial.print("Heater flow state is: " );
       Serial.println(heater_flow_state);
       send(msg_S_HEATER_FLOW_STATE.set(heater_flow_state.c_str()));
    
       //  Serial.print("Heater on/off is: " );
       //  Serial.println((heater_status==true)?"On":"Off");
       //  send(msg_S_HEATER_STATUS.set(heater_status));
    
       //  Serial.print("Heater Temperature is: " );
       //  Serial.println(heater_temp,1);
       //  send(msg_S_HEATER_TEMP.set(heater_temp,1));
    
       Serial.print("Heater Setpoint: " );
       Serial.println(heater_setpoint,1);
       send(msg_S_HEATER_SET_POINT.set(heater_setpoint,1));
    }
    #endif
    
    #ifdef ID_S_DISTANCE
    void distance()
    {
    
       Serial.print("Distance is: " );
       Serial.println(map(randNumber,1,100,0,150));
    
       send(msg_S_DISTANCE.set(map(randNumber,1,100,0,150)));
    
    }
    #endif
    
    #ifdef ID_S_LIGHT_LEVEL
    void light_level()
    {
    
       Serial.print("Light is: " );
       Serial.println(map(randNumber,1,100,0,150));
    
       send(msg_S_LIGHT_LEVEL.set(map(randNumber,1,100,0,150)));
    
    }
    #endif
    
    #ifdef ID_S_LOCK
    void lock()
    {
    
       Serial.print("Lock is: " );
       Serial.println((isLocked ? "Locked":"Unlocked"));
       send(msg_S_LOCK.set(isLocked));
    
    }
    #endif
    
    #ifdef ID_S_IR
    void ir()
    {
    
       Serial.print("Infrared is: " );
       Serial.println(irVal);
    
       send(msg_S_IR_S.set(irVal));
       send(msg_S_IR_R.set(irVal));
    
    }
    #endif
    
    #ifdef ID_S_WATER
    void water()
    {
    
       Serial.print("Water flow is: " );
       Serial.println(map(randNumber,1,100,0,150));
    
       send(msg_S_WATER_F.set(map(randNumber,1,100,0,150)));
    
       Serial.print("Water volume is: " );
       Serial.println(map(randNumber,1,100,0,150));
    
       send(msg_S_WATER_V.set(map(randNumber,1,100,0,150)));
    
    }
    #endif
    
    #ifdef ID_S_AIR_QUALITY
    void air()
    {
    
       Serial.print("Air Quality is: " );
       Serial.println(randNumber);
    
       send(msg_S_AIR_QUALITY.set(randNumber));
    
    }
    #endif
    
    #ifdef ID_S_DUST
    void dust()
    {
    
       Serial.print("Dust level is: " );
       Serial.println(randNumber);
    
       send(msg_S_DUST.set(randNumber));
    
    }
    #endif
    
    #ifdef ID_S_SCENE_CONTROLLER
    void scene()
    {
    
       Serial.print("Scene is: " );
       Serial.println(scenes[sceneVal]);
    
       if(sceneValPrevious != sceneVal) {
       	send(msg_S_SCENE_CONTROLLER_OF.set(sceneValPrevious));
       	send(msg_S_SCENE_CONTROLLER_ON.set(sceneVal));
       	sceneValPrevious=sceneVal;
       }
    
    }
    #endif
    
    #ifdef ID_S_RGB_LIGHT
    void rgbLight()
    {
    
       Serial.print("RGB Light state is: " );
       Serial.println(rgbState);
       send(msg_S_RGB_LIGHT_V_RGB.set(rgbState.c_str()));
    
       Serial.print("RGB Light Watt is: " );
       Serial.println(map(randNumber,1,100,0,150));
       send(msg_S_RGB_LIGHT_V_WATT.set(map(randNumber,1,100,0,150)));
    
    }
    #endif
    
    #ifdef ID_S_RGBW_LIGHT
    void rgbwLight()
    {
    
       Serial.print("RGBW Light state is: " );
       Serial.println(rgbwState);
       send(msg_S_RGBW_LIGHT_V_RGBW.set(rgbwState.c_str()));
    
       Serial.print("RGBW Light Watt is: " );
       Serial.println(map(randNumber,1,100,0,150));
       send(msg_S_RGBW_LIGHT_V_WATT.set(map(randNumber,1,100,0,150)));
    
    }
    #endif
    
    #ifdef ID_S_COLOR_SENSOR
    void color()
    {
       String colorState;
    
       String red   = String(random(0,256),HEX);
       String green = String(random(0,256),HEX);
       String blue  = String(random(0,256),HEX);
    
       colorState=String(red + green + blue);
    
       Serial.print("Color state is: " );
       Serial.println(colorState);
       send(msg_S_COLOR_SENSOR_V_RGB.set(colorState.c_str()));
    
    }
    #endif
    
    #ifdef ID_S_HVAC
    void hvac()
    {
    
       //  float hvac_SetPointHeat = 16.5;
       //  float hvac_SetPointCool = 25.5;
       //  String hvac_FlowState   = "AutoChangeOver";
       //  String hvac_FlowMode    = "Auto";
       //  String hvac_Speed       = "Normal";
    
       Serial.print("HVAC Set Point Heat is: " );
       Serial.println(hvac_SetPointHeat);
       send(msg_S_HVAC_V_HVAC_SETPOINT_HEAT.set(hvac_SetPointHeat,1));
    
       Serial.print("HVAC Set Point Cool is: " );
       Serial.println(hvac_SetPointCool);
       send(msg_S_HVAC_V_HVAC_SETPOINT_COOL.set(hvac_SetPointCool,1));
    
       Serial.print("HVAC Flow State is: " );
       Serial.println(hvac_FlowState);
       send(msg_S_HVAC_V_HVAC_FLOW_STATET.set(hvac_FlowState.c_str()));
    
       Serial.print("HVAC Flow Mode is: " );
       Serial.println(hvac_FlowMode);
       send(msg_S_HVAC_V_HVAC_FLOW_MODE.set(hvac_FlowMode.c_str()));
    
       Serial.print("HVAC Speed is: " );
       Serial.println(hvac_Speed);
       send(msg_S_HVAC_V_HVAC_SPEED.set(hvac_Speed.c_str()));
    
    }
    #endif
    
    #ifdef ID_S_MULTIMETER
    void multimeter()
    {
       int impedance=map(randNumber,1,100,0,15000);
       int volt=map(randNumber,1,100,0,380);
       int amps=map(randNumber,1,100,0,16);
    
       Serial.print("Impedance is: " );
       Serial.println(impedance);
       send(msg_S_MULTIMETER_V_IMPEDANCE.set(impedance));
    
       Serial.print("Voltage is: " );
       Serial.println(volt);
       send(msg_S_MULTIMETER_V_VOLTAGE.set(volt));
    
       Serial.print("Current is: " );
       Serial.println(amps);
       send(msg_S_MULTIMETER_V_CURRENT.set(amps));
    
    }
    #endif
    
    #ifdef ID_S_SPRINKLER
    #endif
    #ifdef ID_S_WATER_LEAK
    #endif
    #ifdef ID_S_SOUND
    #endif
    #ifdef ID_S_VIBRATION
    #endif
    #ifdef ID_S_MOISTURE
    #endif
    
    #ifdef ID_S_MOISTURE
    void moisture()
    {
    
       Serial.print("Moisture level is: " );
       Serial.println(randNumber);
    
       send(msg_S_MOISTURE.set(randNumber));
    }
    #endif
    
    #ifdef ID_S_CUSTOM
    void custom()
    {
    
       Serial.print("Custom value is: " );
       Serial.println(randNumber);
    
       send(msg_S_CUSTOM_1.set(randNumber));
       send(msg_S_CUSTOM_2.set(randNumber));
       send(msg_S_CUSTOM_3.set(randNumber));
       send(msg_S_CUSTOM_4.set(randNumber));
       send(msg_S_CUSTOM_5.set(randNumber));
    
    }
    #endif
    
    
    void receive(const MyMessage &message)
    {
       switch (message.type) {
    #ifdef ID_S_ARMED
       case V_ARMED:
       	isArmed = message.getBool();
       	Serial.print("Incoming change for ID_S_ARMED:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println((isArmed ? "Armed":"Disarmed" ));
    #ifdef ID_S_DOOR
       	door();//temp ack for door
    #endif
    #ifdef ID_S_MOTION
       	motion();//temp ack
    #endif
    #ifdef ID_S_SMOKE
       	smoke();//temp ack
    #endif
       	break;
    #endif
    
    
       case V_STATUS: // V_LIGHT:
    #ifdef ID_S_LIGHT
       	if(message.sensor==ID_S_LIGHT) {
       		isLightOn =  message.getBool();
       		Serial.print("Incoming change for ID_S_LIGHT:");
       		Serial.print(message.sensor);
       		Serial.print(", New status: ");
       		Serial.println((isLightOn ? "On":"Off"));
       		light(); // temp ack
       	}
    #endif
       	//    #ifdef ID_S_HEATER
       	//        if(message.sensor == ID_S_HEATER){
       	//          heater_status = message.getBool();
       	//          Serial.print("Incoming change for ID_S_HEATER:");
       	//          Serial.print(message.sensor);
       	//          Serial.print(", New status: ");
       	//          Serial.println(heater_status);
       	//          heater();//temp ack
       	//        }
       	//    #endif
       	break;
    
    
    #ifdef ID_S_DIMMER
       case V_DIMMER:
       	if ((message.getInt()<0)||(message.getInt()>100)) {
       		Serial.println( "V_DIMMER data invalid (should be 0..100)" );
       		break;
       	}
       	dimmerVal= message.getInt();
       	Serial.print("Incoming change for ID_S_DIMMER:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(message.getInt());
       	dimmer();// temp ack
       	break;
    #endif
    
    #ifdef ID_S_COVER
       case V_UP:
       	coverState=1;
       	Serial.print("Incoming change for ID_S_COVER:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println("V_UP");
       	cover(); // temp ack
       	break;
    
       case V_DOWN:
       	coverState=-1;
       	Serial.print("Incoming change for ID_S_COVER:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println("V_DOWN");
       	cover(); //temp ack
       	break;
    
       case V_STOP:
       	coverState=0;
       	Serial.print("Incoming change for ID_S_COVER:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println("V_STOP");
       	cover(); //temp ack
       	break;
    #endif
    
    
       case V_HVAC_SETPOINT_HEAT:
    
    #ifdef ID_S_HEATER
       	if(message.sensor == ID_S_HEATER) {
       		heater_setpoint=message.getFloat();
    
       		Serial.print("Incoming set point for ID_S_HEATER:");
       		Serial.print(message.sensor);
       		Serial.print(", New status: ");
       		Serial.println(heater_setpoint,1);
       		heater();//temp ack
       	}
    #endif
    
    #ifdef ID_S_HVAC
       	if(message.sensor == ID_S_HVAC) {
       		hvac_SetPointHeat=message.getFloat();
       		Serial.print("Incoming set point for ID_S_HVAC:");
       		Serial.print(message.sensor);
       		Serial.print(", New status: ");
       		Serial.println(hvac_SetPointHeat,1);
       		hvac();//temp ack
       	}
    #endif
       	break;
    
       case V_HVAC_FLOW_STATE:
    #ifdef ID_S_HEATER
       	if(message.sensor == ID_S_HEATER) {
       		heater_flow_state=message.getString();
       		Serial.print("Incoming flow state change for ID_S_HEATER:");
       		Serial.print(message.sensor);
       		Serial.print(", New status: ");
       		Serial.println(heater_flow_state);
       		heater();//temp ack
       	}
    #endif
    
    #ifdef ID_S_HVAC
       	if(message.sensor == ID_S_HVAC) {
       		hvac_FlowState=message.getString();
    
       		Serial.print("Incoming set point for ID_S_HVAC:");
       		Serial.print(message.sensor);
       		Serial.print(", New status: ");
       		Serial.println(hvac_FlowState);
       		hvac();//temp ack
       	}
    #endif
       	break;
    
    #ifdef ID_S_LOCK
       case V_LOCK_STATUS:
       	isLocked =  message.getBool();
       	Serial.print("Incoming change for ID_S_LOCK:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(message.getBool()?"Locked":"Unlocked");
       	lock(); //temp ack
       	break;
    #endif
    
    #ifdef ID_S_IR
       case V_IR_SEND:
       	irVal = message.getLong();
       	Serial.print("Incoming change for ID_S_IR:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(irVal);
       	ir(); // temp ack
       	break;
       case V_IR_RECEIVE:
       	irVal = message.getLong();
       	Serial.print("Incoming change for ID_S_IR:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(irVal);
       	ir(); // temp ack
       	break;
    #endif
    
    #ifdef ID_S_SCENE_CONTROLLER
       case V_SCENE_ON:
       	sceneVal = message.getInt();
       	Serial.print("Incoming change for ID_S_SCENE_CONTROLLER:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.print(scenes[sceneVal]);
       	Serial.println(" On");
       	scene();// temp ack
       	break;
       case V_SCENE_OFF:
       	sceneVal = message.getInt();
       	Serial.print("Incoming change for ID_S_SCENE_CONTROLLER:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.print(scenes[sceneVal]);
       	Serial.println(" Off");
       	scene();// temp ack
       	break;
    #endif
    
    #ifdef ID_S_RGB_LIGHT
       case V_RGB:
       	rgbState=message.getString();
       	Serial.print("Incoming flow state change for ID_S_RGB_LIGHT:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(rgbState);
       	rgbLight(); // temp ack
    
       	break;
    #endif
    
    #ifdef ID_S_RGBW_LIGHT
       case V_RGBW:
       	rgbwState=message.getString();
       	Serial.print("Incoming flow state change for ID_S_RGBW_LIGHT:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(rgbwState);
       	rgbwLight();
       	break;
    #endif
    
    #ifdef ID_S_HVAC
       //  hvac_SetPointHeat
       //  hvac_SetPointCool
       //  hvac_FlowState
       //  hvac_FlowMode
       //  hvac_Speed
    
       case V_HVAC_SETPOINT_COOL:
       	hvac_SetPointCool=message.getFloat();
    
       	Serial.print("Incoming set point for ID_S_HVAC:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(hvac_SetPointCool,1);
       	hvac();//temp ack
       	break;
    
       case V_HVAC_FLOW_MODE:
       	hvac_Speed=message.getString();
    
       	Serial.print("Incoming set point for ID_S_HVAC:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(hvac_Speed);
       	hvac();//temp ack
       	break;
    
       case V_HVAC_SPEED:
       	hvac_FlowMode=message.getString();
    
       	Serial.print("Incoming set point for ID_S_HVAC:");
       	Serial.print(message.sensor);
       	Serial.print(", New status: ");
       	Serial.println(hvac_FlowMode);
       	hvac();//temp ack
       	break;
    #endif
    
       default:
       	Serial.print("Unknown/UnImplemented message type: ");
       	Serial.println(message.type);
       }
    
    }```

  • Mod

    can you try to add the watchdog timers and see what happens? Try using a different bootloader? Different power source or using a small booster or an additional AA battery and a LDO. I am just throwing ideas and see what you can do with the stuff you may have at home.



  • @gohan said in My Slim 2AA Battery Node:

    LDO

    @gohan
    Hi, i added a WDT now into the MotionSensorSketch.
    Well at least i guess i did. I just read about it , never used it before. Does the 1Mhz Optiboot boatloaders support this ?

    Unfortunalty I didnt recieve my 3,3V boosters yet and i dont have LDO´s around.
    Concerning the bootloaders. Do you have a suggestion which one to use ? As I read that sticking to 1Mhz is important when using only 2AA batteries because of instability when voltage goes belowe certian values.
    Obviously i could use more batteries, but then i cant supply the nRF2401 from the board right ?

    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #define MY_NODE_ID 40
    #include <MySensors.h>
    #include <avr/wdt.h>
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 3   // 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()
    {
    	wdt_enable(WDTO_2S);
    	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", "AndyWasHere");
    
    	// 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);
     wdt_reset();
    
    }```

  • Mod

    Actually you would have to put wdt_enable(WDTO_8S); right after Loop() and wdt_disable(); before calling the sleep (this is what I copied from another sketch). The wdt_reset you cold use in the middle of the loop in case you have a function that could take long time to execute and it may trigger the WD timer so you can reset the timer (you can play with the length of the timer according to your needs)



  • @gohan
    maybe like this ?

    void loop()
    
    
    {
    	wdt_enable(WDTO_8S);
    	// 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
    wdt_disable();
    	// Sleep until interrupt comes in on motion sensor. Send update every two minute.
    	sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
     
    
    }```

  • Mod

    that's what I found. You could also use wdt_enable(WDTO_2S) I think. I haven't done any test yet on this.


  • Hardware Contributor

    @Komaandy Try to remove all your Serial.print.



    1. Has anyone used NRF24L01+ + PA + LNA on these modules ?

    2. Any reason why it shouldnt work out of the box ( does AA batteries give enough power to drive them on LOW settings? )

    3. What type of battery monitoring is recommended on these ones? The resistance or the library way?

    I just got 90 PCBs, beautiful, fast shipping ( i think under 2 weeks to Norway ) and looks well made.
    I'll drop one in each beehive I have ( 7 ) and see how long they last



  • So, it seems i made some progress.
    After changing to the @GertSanders bootloader ( https://www.openhardware.io/view/33/Various-bootloader-files-based-on-Optiboot-62) all the PIR nodes seem to be stable.
    I´m using these settings 0_1495738589974_1.PNG

    Wish me luck 🙂


  • Hardware Contributor

    @Komaandy Yes, using 8MHz instead of 1MHz is perhaps a good idea. Stable enough at room temperature, well proven and will e.g. solve a "Serial.print()" interrupt loop issue. Just remember that you'll lose ~25uA if you'll leave BOD enabled.


Log in to reply
 

Suggested Topics

  • 8
  • 7
  • 90
  • 3
  • 1
  • 1

58
Online

11.4k
Users

11.1k
Topics

112.6k
Posts