๐Ÿ’ฌ MySensors NRF5 Platform




  • Contest Winner

    Nice! However from a security point of view I would advice against using ECB mode for encryption as explained here: https://crypto.stackexchange.com/questions/20941/why-shouldnt-i-use-ecb-encryption

    Using message signing combined with encryption helps somewhat as part of the encrypted payload will be random in nature.


  • Contest Winner

    @Anticimex said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    Nice! However from a security point of view I would advice against using ECB mode for encryption as explained here: https://crypto.stackexchange.com/questions/20941/why-shouldnt-i-use-ecb-encryption

    Thank you for the link. At the moment the "encryption" is implemented like it is for NRF24. I have commented it here https://github.com/mysensors/MySensors/pull/830/files#diff-cf14b6301beb3a4dbaded9b95bb190feR673

    The nRF5 series is flexible enough to do a better encryption job. Its also possible to do things like frequency hopping or enable the RX mode at specific time slots to create battery powered actors.


  • Contest Winner

    @d00616 ok, but the encryption for RF24 is also rather useless as it does not use initialization vectors. So the first part of the message (if the message is up to the encryption block size in size) will always yield the same cipher text and thus be predictable. But perhaps this hw handles that. I have not read up on it. I believe the rfm69 radio does since it states that the payload size decreases if encryption is enabled, suggesting that there is room reserved for syncing IV:s.
    Nevertheless, encryption is not the key to security imo. Authentication is. Encryption gives obfuscation.


  • Admin

    @d00616, an impressive first post here in the community. Welcome!

    Great job on porting the library to a new platform.


  • Admin

    @d00616

    BTW. Have you had any time reading up on frequency hopping and how much stay-away-windows affect battery consumption? How is the time synchronization handled between nodes?


  • Hardware Contributor

    @d00616
    very nice work ๐Ÿ‘

    I've also some projects with nrf52832, and waiting for pcb i'll release soon. I'm using raytac modules, was very tempted to try to make my antenna too but for the moment i'm sticking with those modules. I've not tried range yet, what do you get?

    Can't wait to get some 52840 modules.. (a bit expensive for the moment) because package need special pcb.
    Regarding authentication, i have added signing ic (atsha204a i2c) on my boards in case..

    Thank you very much for your porting to Mysensors, that's awesome ๐Ÿ‘


  • Contest Winner

    @Anticimex
    The implemented encryption is in the same state like NRF24. I know about the IV(0) problem, but my first goal was the NRF24 compatibility.

    For an nRF5 only protocol, the hardware AES-CCM encryption can be used. At the moment, I have no plans to start with a new radio protocol. When I should start with, my idea is to use dynamic keys exchanged with micro-ecc. An IV based on a shared part the node id and a value from synchronized RTC.

    Nevertheless, encryption is not the key to security imo. Authentication is. Encryption gives obfuscation.

    I agree here.


  • Contest Winner

    @hek

    @hek said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    BTW. Have you had any time reading up on frequency hopping and how much stay-away-windows affect battery consumption? How is the time synchronization handled between nodes?

    The main problem of frequency hopping is finding the right time slot initially. I have no idea about a good way to implement this.

    When I see the number of retransmits on my location, frequency hopping has no real benefit. What I interested is to use time slots for battery powered actors. The Gateway or Relay needs to cache packages and transmit it at the correct time. The node needs to listen at a specified time. When no data is transmitted the radio can be disabled after the time the address should send. To implement this Shortcuts and a bit counter is available. To use a low power mode to to this, the 32kHz crystal is required.

    I use some of the functionality to disable the radio in the ESB mode when no ACK packet is received or after ACK is received.

    To control this, the RTC trigger points needs to synchronized. Maybe with an protocol extension, but this needs access to the signing logic.

    If you find out what is possible, there is an calculation tool for ANT+ protocol. https://www.thisisant.com/developer/components/developer


  • Contest Winner

    @scalz said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I'm using raytac modules, was very tempted to try to make my antenna too but for the moment i'm sticking with those modules. I've not tried range yet, what do you get?

    I haven't measured the range yet.

    Can't wait to get some 52840 modules.. (a bit expensive for the moment) because package need special pcb.

    I think the final nRF82840 isn't launched yet.


  • Contest Winner

    @d00616 yes I agree that protocol compatibility is priority. I just wanted to point out the current flaws with that encryption but you obviously know what you are doing ๐Ÿ™‚
    Best would be to come up with a solution that was radio agnostic, but for me encryption is not worth spending too much effort on. I'd say it's obscure enough as it is. Combined with signing, I think people will have a hard time breaking into it.


  • Hardware Contributor

    @d00616
    oki. i'll try to do some range tests, and your PR too! when i'll get more time ๐Ÿ™‚
    Would be nice if they would release a better package footprint for the 840..I said this because i've seen Fanstel is selling modules but not so cheap, so i prefer to wait a bit.
    And i agree with you the 832 is already very nice, even if 840 has some nice feature.


  • Contest Winner

    @Anticimex said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    Best would be to come up with a solution that was radio agnostic, but for me encryption is not worth spending too much effort on. I'd say it's obscure enough as it is. Combined with signing, I think people will have a hard time breaking into it.

    What do you think about switching signing and encryption to AES-CCM? AES-CCM is part BLE(AES-CCM) and ZigBee(AES-CCM*) specification and available as hardware unit in NRF5 and other MCU. With AES132A a coprocessor is available.

    AES-CCM provides encryption and authentication. With AES-CCM the SHA code can be removed. http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fccm.html&cp=2_2_0_28&anchor=topic

    My thesis needs testing; I think AES-CCM on an AVR is faster than AES-CBC with SHA signing in Hardware and requires transmitting less data than the actual signing implementation.

    I don't know something about the code size of AVR projects. When 8k are available, it's possible to store a unique AES-128 key per node in 4k. For AES key updates, a second 4k page is required.

    The keys can be managed with the VirtualPage class: https://github.com/d00616/MySensors/blob/add_nrf5_platform/drivers/NVM/VirtualPage.h

    For key exchange a library like micro-ecc is available. A device can authenticated with an preshared secret.

    The IV can be built by the node ID and a counter incremented with every packet and a global distributed timestamp.

    The counter can be stored in EEPROM after ~1000 packages and is rounded up to next 1000 after a reboot of a node.

    If a node counter reaches the end, a new AES-Key is generated and distributed by the gateway.


  • Contest Winner

    @d00616 I don't see how this relate to the signing solution we use. We use HMAC-SHA256. We already have hw support for this in the atsha204a. There is no plan to replace this.
    Encryption is also already existing in certain radios already (like the rfm69). So it will in a sense always be radio specific and needs to be in order to be effective.


  • Contest Winner


  • Contest Winner

    @d00616 I don't however see it as a problem if you implement some underlying security solution specific to nrf5 as long as it don't require protocol "awareness". That's just a bonus so feel free to have a look at that. But things will quite fast become quite messy if we start mixing security schemes in the protocol.
    The signing backend does have versioning support so it is possible to extend it with new schemes, but so far the scheme we use is supported across all radio variants and it would be a pity to give up that compatibility unless the new scheme offer some improvement over the current one.
    The main drawback with the current one is the message size limitation imposed by the current protocol version which forces us to truncate the signatures but in version 3 of the MySensors protocol, this limitation will be overcome by protocol upgrades.


  • Contest Winner

    @Anticimex At the moment I have other priorities than implementing another security solution or protocol for NRF5. Another protocol can be implemented as a second radio driver including breaking the NRF24 compatibility with larger packet sizes and protocol optimization.


  • Contest Winner

    @d00616 with v3 the protocol backwards compatibility will be broken nevertheless in a way which will support the current generic security protocol fully across all radio transports.
    But there are basically two layers. A mysensors layer where signing is handled using HMAC-SHA256 with nonce exchange, timeouts, lock detection and whitelisting. A rf specific layer can implement additional security solutions (typically encryption) that work transparently with the MySensors protocol. For signing, it is probably not needed as we already have that in place, but encryption could be a relevant feature for the lower level layers.


  • Hardware Contributor

    @d00616

    Hi,

    This is a such great addition for this project. For long time I wanted something like this: a RF SOC with pretty good and usable software support and low power also(and a Cortex arch - pff..that's too much :simple_smile: ). I just wanted to congratulate you for your work and bringing this in to MySensors project - it's very neat and useful.

    I tested it and it works just great so far. I would give you 100 likes on openhardware.io if it would be possible :simple_smile: . Thanks once again for your effort.


  • Contest Winner

    @mtiutiu Thank you very much. I like to read your words. Have fun with this port.

    I have started 2014 to work on Sensors based on the nRF51 chips. At this time the MCU was well documented, but Software was only available under an NDA. Without luck, I tried to build a free Arduino version based on RFduino. There are problems with my linker scripts.

    My next attempt was to use RIOT OS as the base for my Sensor project. Later I have found the great MySensors project. I have started to extend the RIOT Arduino layer to let MySensors running. On my research, I found the Arduino port of Sandeep Mistry (thank you!), so it was easier for me add the missing functionality to MySensors and arduino-nrf5 instead to RIOT OS. From this point, I required eight months to a functional MySensors port.



  • Congratulations on winning the contest. That convinces me to give it a try.
    Even though this has been available for months, I'm not seeing much discussion on:

    • Improvements on range.
    • The best module to purchase for the simplest nodes - like temperature.
    • Battery performance.

    Anyone have feedback on those yet?

    Thanks ahead of time


  • Hardware Contributor

    @ileneken3
    I'm having some fun with @d00616 work ๐Ÿ™‚ And it's working fine so far (thx again).

    I have not tested battery performance for the moment.. NRF52 is capable of very low power but i think the low power is not enabled yet in the porting, it's explained in the project prez if i remember

    Regarding range, sure NRF52 is an improved chip compared to NRF24 for instance, but the most important part is the antenna. That's the case for all mcu though. Take a long range capable mcu and a bad antenna choice, or a bad antenna design (bad gnd plane, bad clearance for antenna etc) and you'll never get the long range (example: miniaturized chip antenna, or some pcb antennas too).

    For the simplest devices to buy, no idea as i'm making custom boards.


  • Contest Winner

    @ileneken3 Thank you.

    Like @scalz has written, the range depending mostly on the antenna. With the same antenna the nRF52 series are more efficient.

    If you need a simple module to start with, a RedBear BLE Nano 2 or Nano is a good module. It's a small module with integrated voltage regulator and 2.54mm pins. This module is available in the second generation with compatible pin layout.

    If you need an cheap module, there are some starting at 3-6โ‚ฌ with an nRF51. I don't know how long these modules are sold. If possible, use nRF52 based modules. The nRF52 is faster (https://github.com/mysensors/MySensors/pull/845), more flexible and less current consuming then nRF51. The interrupt vector of the nRF52 can be moved into RAM. This reduces the interrupt latency and allows to implement OTA updates in an simple way.

    Most peripherals (e.g. expect ADC) can be assigned to any IO pin. So you can change the role in arduinos board definition.

    You can find detailed information about the current consumption in the datasheets. The MySensors sleep function consumes 3ยตA until you want to wait for an Interrupt (1mA). To fix this cores/nRF5/WInterrupts.c needs an partitial rewrite. I have no time at the moment to fix this issue. The discussion about how to fix is sleeping: https://github.com/sandeepmistry/arduino-nRF5/issues/153

    Another point to save some energy is to manage the DCDC converter (not available on all boards) in the radio or sleep code. -> https://devzone.nordicsemi.com/question/685/ldo-vs-dcdc-nrf51822/

    More energy savings, requires breaking the compatibility to NRF24 radios and implementing an additional communication protocol. This allows to implement battery powered nodes which can receive packages.

    When issue 153 is fixed, I think the nRF5 platform is a good choice to start new developments of sensors without the CPU and memory limitations of ATMEGA or maybe in the future the limitations of NRF24 radio. When its not fixed this is a good platform for main powered components and sensors which are only waking up by time.


  • Contest Winner

    @scalz said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I have not tested battery performance for the moment.. NRF52 is capable of very low power but i think the low power is not enabled yet in the porting, it's explained in the project prez if i remember

    Low power in implemented at the MySensors side. There is an issue at the Arduino side -> ๐Ÿ’ฌ MySensors NRF5 Platform

    Edit: The radio is saving power in some states. There is a little room for improvments like fast rampup for nRF52. With an NRF24 incompatible protocol there is room for improvements.


  • Contest Winner

    @d00616 I found the current issue is a problem only with older nRF51 hardware. I can't measure the current on with newer nRF51 or nRF52 chips. But a fix is documented in http://infocenter.nordicsemi.com/pdf/nRF51822-pan_v3.0.pdf (s. PAN #39)


  • Hardware Contributor

    @d00616 thx for the info ๐Ÿ‘
    I'll try to measure power consumption asap


  • Hero Member

    FWIW, you may want to delete this passage in your overview, as it's not really accurate:

    Don't buy an nRF5 development kit to program other nRF5 modules. The programmer is hard wired to the nRF5 chip on most DK boards.
    

    In fact, Nordic has this video that I just now came across on how to do it:
    Nordic Semiconductor - Programming and debugging custom nRF5 devices – 04:10
    — Nordic Semiconductor

    IMHO, I think the DK is a good way for noobs to get started, because the setup is well supported for the onboard nRF52 and "just works." The fact that it can later be used to program external nRF5 devices is a nice (and very poorly advertised) bonus. The DK has a real Segger J-Link on the DK board.

    That being said, the DK is not the cheapest option, so noobs may need to weigh "easy" vs "cheap" in their purchase decision.



  • I am having problems compiling the Mockmysensors example on the waveshare board.

    If you comment out all sensors and uncomment
    #define ID_S_MULTIMETER 28

    I get the following error:
    exit status 1
    call of overloaded 'set(int&)' is ambiguous


  • Hero Member

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I am having problems compiling the Mockmysensors example on the waveshare board.

    If you comment out all sensors and uncomment
    #define ID_S_MULTIMETER 28

    I get the following error:
    exit status 1
    call of overloaded 'set(int&)' is ambiguous

    Did you remember to do this?

    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_NRF5_ESB
    


  • @NeverDie
    Yes did that.
    Strange though if you run the sketch with just the first 2 sensors uncommented it compiles fine.
    It must me something to do with multimeter?


  • Hero Member

    At least on my system, if I don't uncomment anything (other than the passage I just indicated), it at least compiles. Haven't actually tried to see if it works yet....


  • Hero Member

    Well, I just tried what you queried about, and it compiles fine on my system:

    /*
    * 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_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #define MY_NODE_ID 254
    
    #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    5  // 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 = 900000; // 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);
    	}
    
    }
    
    
    

  • Hero Member

    Oops. Uncommented the wrong thing. I'll try again.


  • Hero Member

    OK, confirmed. The full error message is:

    
    
    Build options changed, rebuilding all
    C:\Users\CoolerMaster\Documents\Arduino\mysensors sketches\mockmysensors\MockMySensors_v002\MockMySensors_v002.ino: In function 'void multimeter()':
    
    MockMySensors_v002:1183: error: call of overloaded 'set(int&)' is ambiguous
    
      send(msg_S_MULTIMETER_V_IMPEDANCE.set(impedance));
    
                                                     ^
    
    In file included from C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/MySensors.h:364:0,
    
                     from C:\Users\CoolerMaster\Documents\Arduino\mysensors sketches\mockmysensors\MockMySensors_v002\MockMySensors_v002.ino:20:
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:269:12: note: candidate: MyMessage& MyMessage::set(bool)
    
     MyMessage& MyMessage::set(bool value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:277:12: note: candidate: MyMessage& MyMessage::set(uint8_t)
    
     MyMessage& MyMessage::set(uint8_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:294:12: note: candidate: MyMessage& MyMessage::set(uint32_t)
    
     MyMessage& MyMessage::set(uint32_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:302:12: note: candidate: MyMessage& MyMessage::set(int32_t)
    
     MyMessage& MyMessage::set(int32_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:310:12: note: candidate: MyMessage& MyMessage::set(uint16_t)
    
     MyMessage& MyMessage::set(uint16_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:318:12: note: candidate: MyMessage& MyMessage::set(int16_t)
    
     MyMessage& MyMessage::set(int16_t value)
    
                ^
    
    MockMySensors_v002:1187: error: call of overloaded 'set(int&)' is ambiguous
    
      send(msg_S_MULTIMETER_V_VOLTAGE.set(volt));
    
                                              ^
    
    In file included from C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/MySensors.h:364:0,
    
                     from C:\Users\CoolerMaster\Documents\Arduino\mysensors sketches\mockmysensors\MockMySensors_v002\MockMySensors_v002.ino:20:
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:269:12: note: candidate: MyMessage& MyMessage::set(bool)
    
     MyMessage& MyMessage::set(bool value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:277:12: note: candidate: MyMessage& MyMessage::set(uint8_t)
    
     MyMessage& MyMessage::set(uint8_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:294:12: note: candidate: MyMessage& MyMessage::set(uint32_t)
    
     MyMessage& MyMessage::set(uint32_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:302:12: note: candidate: MyMessage& MyMessage::set(int32_t)
    
     MyMessage& MyMessage::set(int32_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:310:12: note: candidate: MyMessage& MyMessage::set(uint16_t)
    
     MyMessage& MyMessage::set(uint16_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:318:12: note: candidate: MyMessage& MyMessage::set(int16_t)
    
     MyMessage& MyMessage::set(int16_t value)
    
                ^
    
    MockMySensors_v002:1191: error: call of overloaded 'set(int&)' is ambiguous
    
      send(msg_S_MULTIMETER_V_CURRENT.set(amps));
    
                                              ^
    
    In file included from C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/MySensors.h:364:0,
    
                     from C:\Users\CoolerMaster\Documents\Arduino\mysensors sketches\mockmysensors\MockMySensors_v002\MockMySensors_v002.ino:20:
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:269:12: note: candidate: MyMessage& MyMessage::set(bool)
    
     MyMessage& MyMessage::set(bool value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:277:12: note: candidate: MyMessage& MyMessage::set(uint8_t)
    
     MyMessage& MyMessage::set(uint8_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:294:12: note: candidate: MyMessage& MyMessage::set(uint32_t)
    
     MyMessage& MyMessage::set(uint32_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:302:12: note: candidate: MyMessage& MyMessage::set(int32_t)
    
     MyMessage& MyMessage::set(int32_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:310:12: note: candidate: MyMessage& MyMessage::set(uint16_t)
    
     MyMessage& MyMessage::set(uint16_t value)
    
                ^
    
    C:\Users\CoolerMaster\Documents\Arduino\libraries\MySensors-development/core/MyMessage.cpp:318:12: note: candidate: MyMessage& MyMessage::set(int16_t)
    
     MyMessage& MyMessage::set(int16_t value)
    
                ^
    
    exit status 1
    call of overloaded 'set(int&)' is ambiguous
    


  • @NeverDie
    Ha Yes Sprinkler works fine.



  • @NeverDie
    So after running through all the sensors in the mockmysensors sketch there are quite a few that have the same problem.
    I have done the same tests on my standard setup ATmega328 and all compile ok.
    I also tried some of my own small sketches on both platforms and had problems on the nrf5 platform with the same error.
    So is this a mySensors problem or is it something deeper?.
    Why should it not work on both as far as the syntax is concerned.
    Who if anybody do i report the problem too?

    I took the plunge and ordered a jlink/v2 programmer and a waveshare BLE400 motherboard and core module (I know it is nrf51822 but it is a start) but i hope the above problem can be sorted out.


  • Hero Member

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    there are quite a few that have the same problem.

    Yes, the ones I noticed that seem to have the problem are: motion, smoke, dimmer, cover, scene controller, and, of course, multimeter. The rest compiled.

    I don't know the answers to your other good questions, but AFAIK @d00616 appears to be the point man. Perhaps @d00616 can comment?

    Also, if you're not already aware of it, @rmtucker I invite you to join in on the constantly evolving discussion at: https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/498



  • @NeverDie

    After trawling through posts on the forum the following changes compile ok.
    Altered int to uint16_t

    #ifdef ID_S_MULTIMETER
    void multimeter()
    {
    	uint16_t impedance=map(randNumber,1,100,0,15000);
    	uint16_t volt=map(randNumber,1,100,0,380);
    	uint16_t 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```


  • @NeverDie
    After adding a Few uint16_t the whole sketch now compiles with all the sensors turned on and only uses 19% of available memory space ๐Ÿ˜ƒ ,could never have done that on the ATmega platform.
    Just wish we could work out why it had to be changed

    /*
    * 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_RADIO_NRF5_ESB
    #define MY_NODE_ID 254
    
    #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    5  // 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 = 900000; // 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);
    uint16_t 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((uint16_t) 1));
    	} else {
    		Serial.println("Quiet");
    		send(msg_S_MOTION_T.set((uint16_t) 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((uint16_t) 1));
    	} else {
    		Serial.println("Quiet");
    		send(msg_S_SMOKE_T.set((uint16_t) 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((uint16_t) 1));
    	} else if (coverState == -1) {
    		Serial.println("Closing");
    		send(msg_S_COVER_D.set((uint16_t) 0));
    	} else {
    		Serial.println("Idle");
    		send(msg_S_COVER_S.set((uint16_t) -1));
    	}
    	send(msg_S_COVER_V.set((uint16_t) 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((uint16_t) sceneValPrevious));
    		send(msg_S_SCENE_CONTROLLER_ON.set((uint16_t) 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()
    {
    	uint16_t impedance=map(randNumber,1,100,0,15000);
    	uint16_t volt=map(randNumber,1,100,0,380);
    	uint16_t 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);
    	}
    
    }```

  • Contest Winner

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    After trawling through posts on the forum the following changes compile ok.
    Altered int to uint16_t

    This issue seems to be an 32 bit platform issue. With SAMD I see equal error messages. This needs fixing at message level.



  • @d00616
    So is this a mysensors issue and will you rase this issue please.


  • Contest Winner

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    So is this a mysensors issue and will you rase this issue please.

    I have ask the other members of the core team if someone can take a look at this issue. I have time to do this not earlier than Sunday.



  • @NeverDie
    Just wondering about mysensors debug.
    If you have the jlink plugged in for programming but you also want to see the mysensors debug.
    Where is the ftdi adapter plugged in to for tx and rx ?
    And also i suspect that the vcc is not connected on the ftdi adapter because the jlink is supplying the board?
    Oh so many questions??


  • Hero Member

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    Where is the ftdi adapter plugged in to for tx and rx ?

    That's determined by the "board" that you tell the compiler you are using. For example, on the nRF52 DK, the Rx pin is on P0.06. Presently, for simplicity, when I compile for the Ebyte module, I tell the Arduino IDE that it's an nRF52 DK, so then Rx is also on P0.06 and Tx is on P0.08.
    A more advanced way of doing it is to tell the Arduino IDE that the board is a "MyNrf5Board nRF52832", and then you can use d00616's method of pin mapping to make the Rx pin whichever of the mappable pins you want. That's a bit more involved though.

    And also i suspect that the vcc is not connected on the ftdi adapter because the jlink is supplying the board?

    Right. For old fashioned debugging using serial.println(), just Rx and GND is all I use.



  • @NeverDie
    Disappointed so far with the NRF51822.๐Ÿ˜ฆ
    Basically it can not connect to any i2c sensors which mysensors relies on heavily.
    So not a lot can be done with it.
    It does integrate with mysensors well though,proved that with mockmysensors sketch.
    I dare not even try the spi interface.
    I would advise not trying this till the i2c problems are sorted out.
    At the moment it is running Blinky and thats it.


  • Contest Winner

    @rmtucker can't you just bit bang the I2C sensors? Should not be any mcu incapable of that. There should be plenty drivers available that implement a bit banged I2C driver.



  • @Anticimex
    I managed to get a nokia 5110 display connected and working using the u8glib and softspi.
    I can not get the easier to use adafruit library to compile though.
    Nor have i been able to find a Soft i2c library that will compile without errors.
    So i am afraid i2c is still a non starter.


  • Hardware Contributor

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    So i am afraid i2c is still a non starter.

    maybe try this one https://github.com/felias-fogg/SlowSoftWire
    I don't use it, but it compiles fine for nrf52. I already tested it a while ago, and it worked for me.



  • @scalz
    my head is battered with this.
    tried the library you mentioned and it compiled fine but still gave spurious readings.
    so i plugged the htu21d back in to a nano and used the sparkfun library demo.
    the readings were perfect.
    so frustrated with this because all my nodes use i2c sensors.


  • Hero Member

    @rmtucker
    Stupid question, but are your i2c sensors getting all the voltage that they need? After all, a nano runs at 5v, right? I know that some of the TH i2c sensors include voltage regulators, which would drop the voltage even further. If necessary, those could be removed. That's what I generally do.



  • @NeverDie
    Yes They are 3.3v sensors.
    What we need is someone else using nrf51822 and i2c sensors that can shine some light.


  • Hardware Contributor

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    @NeverDie
    Yes They are 3.3v sensors.
    What we need is someone else using nrf51822 and i2c sensors that can shine some light.

    I'll try soon, hopefully I'll have time tomorrow, my nrf51 module is soldered on a breadboard. I need to make the promised tests on the nrf52 too ...



  • @Nca78
    Just an observation after many hours of tinkering.
    There is no problem reading one byte back from i2c,like when doing an i2c scan.
    It comes back with the address of the htu21d no problem.
    But if you try to read 3 bytes which is what you do when reading the temp etc,it goes T*TS up.



  • Well guys after all that ๐Ÿ˜ฆ
    I had not installed the development version from git.๐Ÿ˜ 
    After installling the development version the i2c is working fine.
    Suprised no one else has done this??

    From git (for core development)
    
    Follow steps from Board Manager section above
    cd <SKETCHBOOK>, where <SKETCHBOOK> is your Arduino Sketch folder:
    OS X: ~/Documents/Arduino
    Linux: ~/Arduino
    Windows: ~/Documents/Arduino
    Create a folder named hardware, if it does not exist, and change directories to it
    Clone this repo: git clone https://github.com/sandeepmistry/arduino-nRF5.git sandeepmistry/nRF5
    Restart the Arduino IDE```


  • @rmtucker

    Please can someone update the instructions below to mention installing the development version

    Preparing Arduino
    Arduino doesn't support the nRF5 platform in a standard setup. You have to add the arduino-nRF5 platform via Arduino's Board Manager like described in https://github.com/sandeepmistry/arduino-nRF5/#installing
    
    

  • Hardware Contributor

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    Please can someone update the instructions below to mention installing the development version

    Preparing Arduino
    Arduino doesn't support the nRF5 platform in a standard setup. You have to add the arduino-nRF5 platform via Arduino's Board Manager like described in https://github.com/sandeepmistry/arduino-nRF5/#installing
    
    

    @d00616 maybe ? ๐Ÿ™‚


  • Hero Member

    If there are multiple libraries with the same name (as there seem to be), then how does the compiler know which one to pick? Is it just the first one whose name matches in whatever pathway it follows? Since it obviously compiled even though rmtucker was missing the proper libraries... this just sounds like a heartache waiting to happen unless everything is setup just-so. rmtucker's case seems to prove there won't be any warnings if it picks the wrong one.


  • Hardware Contributor

    looking at d00616 howto it's explained to use Mysensors development branch (or maybe he added it today ๐Ÿ™‚ ). but that makes sense as this port is newer than master branch.

    @NeverDie
    it uses the core libraries depending on the board used in Arduino.


  • Mod

    @scalz: I think @rmtucker was discussing using the development version of the sandeepmistry nrf5 Arduino library, it was not related to the MySensors library.



  • @mfalkvidd
    Sorry i should have made it more understandable.
    When you follow the instructions below as per sandeeps site it does not install the latest NR5 libraries that you see on github.

    Installing
    
    Board Manager
    
    Download and install the Arduino IDE (At least v1.6.12)
    Start the Arduino IDE
    Go into Preferences
    Add https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json as an "Additional Board Manager URL"
    Open the Boards Manager from the Tools -> Board menu and install "Nordic Semiconductor nRF5 Boards"
    Select your nRF5 board from the Tools -> Board menu
    

    Following this you must install the development version aswell which is what you see on github by doing this.

    From git (for core development)
    
    Follow steps from Board Manager section above
    cd <SKETCHBOOK>, where <SKETCHBOOK> is your Arduino Sketch folder:
    OS X: ~/Documents/Arduino
    Linux: ~/Arduino
    Windows: ~/Documents/Arduino
    Create a folder named hardware, if it does not exist, and change directories to it
    Clone this repo: git clone https://github.com/sandeepmistry/arduino-nRF5.git sandeepmistry/nRF5
    Restart the Arduino IDE
    

    Otherwise you run into all kinds of problems using the old library.


  • Contest Winner

    I have added a note at the end of the installation documentation. To make things easier, I have opened an issue to update the Arduino-nRF5 release.

    https://github.com/sandeepmistry/arduino-nRF5/issues/182


  • Contest Winner

    I2C should be fixed now. Version 0.4.0 is released!



  • @d00616
    So should i be able to delete the hardware folder that the development version created from github and just update from boards manager?.


  • Contest Winner

    @rmtucker said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    So should i be able to delete the hardware folder that the development version created from github and just update from boards manager?.

    If this don't work, remove all folder created by hardware and boards manager, close Arduino IDE and reinstall it via Boards Manager.



  • Hi, I don't us nrf52 yet but as i'm a platformio supporter, There is a new release for nrf52 platform with initial arduino framework support ! Good news, i think I will test nrf52 in few weeks.
    https://github.com/platformio/platform-nordicnrf52/releases/tag/v1.2.0


  • Hero Member

    @d00616 said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I2C should be fixed now. Version 0.4.0 is released!

    To help clarify for others who are reading this: the Arduino IDE board manager let me upgrade to 0.4.0 from 0.3.0 by just clicking on the board entry "Nordic Semiconductor NRF5 Boards by Sandeep Mistry", selecting the 0.4.0 version, and then clicking Install.


  • Contest Winner

    1. I have updated the radio driver with fixes for some hardware errata.
    2. I have updated the https://github.com/mysensors/ArduinoHwNRF5 with an enhanced definition format. File name and contents are changed! The board description is compatible with the NRF5 variant provided by Arduino, but it's not possible to use this variant at the moment.

  • Hero Member

    @d00616 said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I have updated the radio driver with fixes for some hardware errata.

    Where do we find the update? i.e. is it baked into the regular MySensors development code thread, or is it elsewhere?


  • Hero Member

    I'm guessing it's this one? https://github.com/mysensors/ArduinoHwNRF5


  • Hero Member

    I refreshed all the libraries. I'm able to compile and upload my sketches, but now it complains a lot about "invalid libraries."

    WARNING: Spurious .ci folder in 'MySensors' library
    WARNING: Spurious .mystools folder in 'MySensors' library
    Sketch uses 3836 bytes (0%) of program storage space. Maximum is 524288 bytes.
    Open On-Chip Debugger 0.10.0-dev-00254-g696fc0a (2016-04-10-10:13)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    debug_level: 0
    0
    adapter speed: 10000 kHz
    cortex_m reset_config sysresetreq
    nrf52.cpu: target state: halted
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x000006e8 msp: 0x20010000
    ** Programming Started **
    auto erase enabled
    wrote 4096 bytes from file C:\Users\David\AppData\Local\Temp\arduino_build_255419/Interrupt_button_test_v005.ino.hex in 0.800001s (5.000 KiB/s)
    ** Programming Finished **
    ** Verify Started **
    verified 3964 bytes in 0.060000s (64.518 KiB/s)
    ** Verified OK **
    ** Resetting Target **
    shutdown command invoked
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\arduino-nRF5: C:\Users\David\Documents\Arduino\libraries\arduino-nRF5
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5: C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\arduino-nRF5: C:\Users\David\Documents\Arduino\libraries\arduino-nRF5
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5: C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5
    

  • Contest Winner

    @NeverDie said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I refreshed all the libraries. I'm able to compile and upload my sketches, but now it complains a lot about "invalid libraries."

    At the moment, I cannot reproduce this with Linux and Arduino 1.8.2. I try to find out what's wrong.


  • Contest Winner

    @d00616 said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    @NeverDie said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I refreshed all the libraries. I'm able to compile and upload my sketches, but now it complains a lot about "invalid libraries."

    At the moment, I cannot reproduce this with Linux and Arduino 1.8.2. I try to find out what's wrong.

    Can you try to remove the .ci and .mystools folders?


  • Hero Member

    @d00616 said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    Can you try to remove the .ci and .mystools folders?

    Done. So, here it is now:

    Archiving built core (caching) in: C:\Users\David\AppData\Local\Temp\arduino_cache_16539\core\core_MySensors_nRF5_MyBoard_nRF52832_bootcode_none,lfclk_lfxo,reset_notenable_2d457965a40837233e636c052c58b359.a
    Sketch uses 3872 bytes (0%) of program storage space. Maximum is 524288 bytes.
    Open On-Chip Debugger 0.10.0-dev-00254-g696fc0a (2016-04-10-10:13)
    Licensed under GNU GPL v2
    For bug reports, read
    	http://openocd.org/doc/doxygen/bugs.html
    debug_level: 0
    0
    adapter speed: 10000 kHz
    cortex_m reset_config sysresetreq
    nrf52.cpu: target state: halted
    target halted due to debug-request, current mode: Thread 
    xPSR: 0x01000000 pc: 0x0000070c msp: 0x20010000
    ** Programming Started **
    auto erase enabled
    wrote 4096 bytes from file C:\Users\David\AppData\Local\Temp\arduino_build_610023/Interrupt_button_test_v006.ino.hex in 0.800001s (5.000 KiB/s)
    ** Programming Finished **
    ** Verify Started **
    verified 4000 bytes in 0.060000s (65.104 KiB/s)
    ** Verified OK **
    ** Resetting Target **
    shutdown command invoked
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\arduino-nRF5: C:\Users\David\Documents\Arduino\libraries\arduino-nRF5
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5: C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\arduino-nRF5: C:\Users\David\Documents\Arduino\libraries\arduino-nRF5
    Invalid library found in C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5: C:\Users\David\Documents\Arduino\libraries\ArduinoHwNRF5
    

    BTW, I'm using the Windows version of Arduino IDE 1.8.5, which is the most current.


  • Contest Winner

    @NeverDie said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    BTW, I'm using the Windows version of Arduino IDE 1.8.5, which is the most current.

    I don't know the correct path on an Windows system. On my system the Sketches are in the ~/Arduino folder in my home directory (~). The arduino-nrf5 is in ~/.arduino15/packages/sandeepmistry/hardware/nRF5/0.4.0 and the ArduinoHwNRF5 files are in ~/.arduino15/packages/MySensors/hardware/nRF5/0.2.1


  • Mod

    on my Windows machine, all boards are located in c:\Users<username>\AppData\Local\Arduino15\packages
    Strange that they've been installed to C:\Users\David\Documents\Arduino\libraries\ on your machine.

    Maybe just delete the folders and re-install using the board manager?


  • Hero Member

    @mfalkvidd All I know is that if I put a library in the folder: C:\Users\David\Documents\Arduino\libraries
    it always gets detected and used. It also means you can completely uninstall/re-install the arduino IDE, and nothing gets lost. I'm not sure about other locations.

    Am I the only one doing it this way?


  • Mod

    @NeverDie for libraries, doing what you do should result in the same behavior as when using the Library Manager.
    But I'm not sure it works with boards (especially given that the Arduino IDE complains when you put boards in the libraries folder).


  • Hero Member

    I use the board manager to manage the boards. I believe it connects directly into github.

    Anyhow, I stripped out all the non-library stuff, and now Windows IDE works without complaining.


  • Hero Member

    Has anyone here yet figured out how to have more than one type of interrupt at a time wake-up the MCU from sleep? Based on the examples so far, it seems as though only one type at a time can be active. I'm sure there must be some way to do it. For instance, it would be desirable if the MCU could wake up not just from a timer event every, say, 5 minutes, to take a temperature reading, but also immediately if there is a leak detected. Right now it's just one or the other.



  • @NeverDie

    So we can not use the normal statement

    int8_t sleep(int interrupt, int mode, unsigned long ms=0);

    I did not realize that was the case as i have never tried it.


  • Hero Member

    I believe hwSleep(..) is the preferred incantation, but beyond that I'm not sure of anything. Maybe @d00616 can comment?

    I should be receiving a number of different PCB projects tomorrow for final assembly and test, and if I can't resolve this soon, I'm simply going to release them without full demo code.


  • Hardware Contributor

    @NeverDie said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    I believe hwSleep(..) is the preferred incantation, but beyond that I'm not sure of anything.

    In MySensors, the regular way to use sleep mode is by using the sleep() functions:
    https://www.mysensors.org/download/sensor_api_20#sleeping

    But like you said, you can also use the raw hwSleep() from the hw abstraction layer. Or you could also rewrite it!
    Which means at each abstraction layer, there are additional logics. sleep() functions have more logics (regarding MySensors states and features) than the raw hwSleep for example (like testing if there is an ongoing ota, smartsleep, heartbeat etc..). I have nodes where i use raw or not, but it's good to know what's behind.



  • @scalz
    So the statement
    int8_t sleep(int interrupt, int mode, unsigned long ms=0);
    Can be used for timer and pin interrupt at he same time on the NRF5 platform just like the arduino?


  • Hero Member

    I'll try it, but I have strong doubts that it's going to work.

    FWIW, here's the pin mapping currently being supplied by digitalPinToInterrupt(..) for the nRF5:
    Digital pin 0 = interrupt pin 0
    Digital pin 1 = interrupt pin 1
    Digital pin 2 = interrupt pin 2
    Digital pin 3 = interrupt pin 3
    Digital pin 4 = interrupt pin 4
    Digital pin 5 = interrupt pin 5
    Digital pin 6 = interrupt pin 6
    Digital pin 7 = interrupt pin 7
    Digital pin 8 = interrupt pin 8
    Digital pin 9 = interrupt pin 9
    Digital pin 10 = interrupt pin 10
    Digital pin 11 = interrupt pin 11
    Digital pin 12 = interrupt pin 12
    Digital pin 13 = interrupt pin 13
    Digital pin 14 = interrupt pin 14
    Digital pin 15 = interrupt pin 15
    Digital pin 16 = interrupt pin 16
    Digital pin 17 = interrupt pin 17
    Digital pin 18 = interrupt pin 18
    Digital pin 19 = interrupt pin 19
    Digital pin 20 = interrupt pin 20
    Digital pin 21 = interrupt pin 21
    Digital pin 22 = interrupt pin 22
    Digital pin 23 = interrupt pin 23
    Digital pin 24 = interrupt pin 24
    Digital pin 25 = interrupt pin 25
    Digital pin 26 = interrupt pin 26
    Digital pin 27 = interrupt pin 27
    Digital pin 28 = interrupt pin 28
    Digital pin 29 = interrupt pin 29
    Digital pin 30 = interrupt pin 30


  • Hero Member

    The last I heard, from @d00616 , we had to supply code such as:

        // Enable interrupt
      NVIC_SetPriority(RTC0_IRQn, 15);
      NVIC_ClearPendingIRQ(RTC0_IRQn);
      NVIC_EnableIRQ(RTC0_IRQn);
    
    

    and

    // This must be in one line
    extern "C" { void RTC0_IRQHandler(void) {rtcInterruptCounter++; NRF5_RESET_EVENT(NRF_RTC0->EVENTS_OVRFLW); NRF_RTC0->EVENTS_OVRFLW=0; }}
    

    to get interrupts to work. Even with that approach, though, I haven't gotten it to support any interrupts in addition to a timed sleeping, though I have gotten it to support one interrupt that's separate from a timed sleeping (basically, sleeps indefinitely until the interrupt happens).


  • Hero Member

    OK, I just now tried:

      sleep(3,CHANGE,3000);
    

    and, as I suspected, it does nothing but sleep for 3 seconds. It's not responsive to any changes on pin P03 on an nRF52.

    @scalz Are you getting a different result? It seems like there's a strong disconnect somewhere between what you're recommending and what I am experiencing.


  • Hardware Contributor

    @NeverDie said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    @scalz Are you getting a different result? It seems like there's a strong disconnect somewhere between what you're recommending and what I am experiencing.

    I didn't give any recommandation, you misread. I just said the regular way to use sleep feature in mysensors, for users, is with sleep(..). But I agree, I misread you too! when you were asking for the specific nrf52 case I guess ๐Ÿ™‚

    That said, I got this working when I made my recessed node for door (accelerometer and hall effect sensor with sleeping). Maybe things have changed in the lib?? or not. I'm struggling between different version of the lib, and some are different from the dev branch.. I'll recheck this asap (not sure for this evening).


  • Hero Member

    I tried toying around with it a bit, and I got a useful result:

    #define MY_CORE_ONLY
    
    #include <nrf.h>
    #include <MySensors.h>
    
    
    const byte ledPin = LED_BUILTIN;
    const byte interruptPin = 3;
    volatile byte state = LOW;
    
    void blinkityBlink(uint8_t pulses, uint8_t repetitions) {
      for (int x=0;x<repetitions;x++) {
        for (int i=0;i<pulses;i++) {
          digitalWrite(LED_BUILTIN,HIGH);
          wait(20);
          digitalWrite(LED_BUILTIN,LOW);
          wait(100);
        }    
          wait(500);
      }
    }
    
    void setup() {
      hwPinMode(LED_BUILTIN,OUTPUT_D0H1);
      hwPinMode(interruptPin, INPUT);
      attachInterrupt(digitalPinToInterrupt(interruptPin), blink, RISING);
      blinkityBlink(2,1);  //signify power-on and start of main loop
    }
    
    volatile bool buttonPressed=false;
    void loop() {
      state = !state;
      digitalWrite(ledPin, state);
      sleep(digitalPinToInterrupt(interruptPin), RISING, 3000);
      wait(20);  //wait 20 milliseconds for button to debounce if it was pressed
      if (digitalRead(interruptPin)) { //if button is pressed
        blinkityBlink(2,1);
      }
      if (buttonPressed) {
        buttonPressed=false;
        blinkityBlink(20,1);
      }
    }
    
    void blink() {
      buttonPressed=true;
    }
    

    So, with this approach, pushing the button on pin 3 does wake up the nRF52 from sleep, whereupon the button press can still be detected and serviced, but it also demonstrates that the ISR per se isn't working.

    Anyhow, with this I'm able to get the PIR or leak sensor or magnet sensor or light sensor doing useful things in a timely manner, even if it isn't ideal. That puts me further ahead than I was before. ๐Ÿ™‚



  • @NeverDie
    This is a test program that wakes up from either that i was using some time ago.

    /**
       The MySensors Arduino library handles the wireless radio link and protocol
       between your home built sensors/actuators and HA controller of choice.
       The sensors forms a self healing radio network with optional repeaters. Each
       repeater and gateway builds a routing tables in EEPROM which keeps track of the
       network topology allowing messages to be routed to nodes.
    
       Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       Copyright (C) 2013-2015 Sensnology AB
       Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    
       Documentation: http://www.mysensors.org
       Support Forum: http://forum.mysensors.org
    
       This program is free software; you can redistribute it and/or
       modify it under the terms of the GNU General Public License
       version 2 as published by the Free Software Foundation.
    
     *******************************
    
       REVISION HISTORY
       Version 1.0 - Henrik EKblad
    
       DESCRIPTION
       This sketch provides an example how to implement a distance sensor using HC-SR04
       Use this sensor to measure KWH and Watt of your house meeter
       You need to set the correct pulsefactor of your meeter (blinks per KWH).
       The sensor starts by fetching current KWH value from gateway.
       Reports both KWH and Watt back to gateway.
    
       Unfortunately millis() won't increment when the Arduino is in
       sleepmode. So we cannot make this sensor sleep if we also want
       to calculate/report watt-number.
       http://www.mysensors.org/build/pulse_power
    */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <MySensors.h>
    #include <Wire.h> // must be included here so that Arduino library object file references work
    #include <RtcDS3231.h>
    RtcDS3231<TwoWire> Rtc(Wire);
    
    #define DIGITAL_INPUT_SENSOR 2  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000       // Nummber of blinks per KWH of your meeter
    //#define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
    #define MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
    #define CHILD_ID 1              // Id of the sensor child
    
    unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    double ppwh = ((double)PULSE_FACTOR) / 1000; // Pulses per watt hour
    //bool pcReceived = false;
    volatile unsigned long pulseCount = 0;
    volatile unsigned long lastBlink = 0;
    volatile unsigned long watt = 0;
    volatile unsigned long kwh = 0;
    unsigned long oldWatt = 0;
    double oldKwh;
    unsigned long lastSend;
    MyMessage wattMsg(CHILD_ID, V_WATT);
    MyMessage kwhMsg(CHILD_ID, V_KWH);
    
    
    void setup()
    {
      Serial.begin(115200);
      Rtc.Begin();
      Rtc.Enable32kHzPin(false);
      Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
      Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
    
      // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
      // If no pullup is used, the reported usage will be too high because of the floating pin
      hwPinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
    
      attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, FALLING);
      //pcReceived = true;
      lastSend = millis();
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Energy Meter", "1.0");
    
      // Register this device as power sensor
      present(CHILD_ID, S_POWER);
    }
    
    void loop()
    {
      unsigned long now = millis();
      // Only send values at a maximum frequency or woken up from sleep
      bool sendTime = now - lastSend > SEND_FREQUENCY;
      if (sendTime) {
        // New watt value has been calculated
        if (watt != oldWatt) {
          // Check that we dont get unresonable large watt value.
          // could hapen when long wraps or false interrupt triggered
          if (watt < ((unsigned long)MAX_WATT)) {
            send(wattMsg.set(watt));  // Send watt value to gw
          }
          Serial.print("Watt:");
          Serial.println(watt);
          oldWatt = watt;
        }
    
        // Pulse count has changed
        //kwh = pulseCount;
        //double kwh = ((double)pulseCount / ((double)PULSE_FACTOR));
        send(kwhMsg.set(pulseCount));  // Send kwh value to gw
        Serial.print("Wh = ");
        Serial.println(pulseCount);
        pulseCount = 0;
        lastSend = now;
      }
      sleep(SEND_FREQUENCY);
    }
    
    void receive(const MyMessage &message)
    {
    }
    
    void onPulse()
    {
      unsigned long newBlink = micros();
      unsigned long interval = newBlink - lastBlink;
      if (interval < 50000L) { // Sometimes we get interrupt on RISING
        return;
      }
      watt = (3600000000.0 / interval) / ppwh;
      lastBlink = newBlink;
      pulseCount++;
    }
    

  • Hero Member

    Well, that's interesting. In the sketch I posted, I invoked sleep with:

      sleep(digitalPinToInterrupt(interruptPin), RISING, 3000);
    

    which caused the mcu to wake up immediately after I press the button, but it didn't process the ISR.

    Using an invocation like yours in the sketch you just posted above:

      sleep(3000);
    

    the ISR executes and then terminates when I press the button, but the MCU doesn't wake and continue with the loop as it did with the prior incantation. Instead, it has to wait for the timer cycle to finish.

    What I want is for it to wake up, do the ISR, and continue with the loop where it left off until it is explicitly put back to sleep again. How do I do that?


  • Contest Winner

    @NeverDie I have checked the sleep routine in all three variants. It's working with my setup.

    There is no API stopping the sleep() by another ISR. Sleep only ends at one of the given conditions.

    When you use the MY_CORE_ONLY define, please add "hwInit();" into the setup() routine.


  • Hero Member

    @d00616 said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    @NeverDie I have checked the sleep routine in all three variants. It's working with my setup.

    There is no API stopping the sleep() by another ISR. Sleep only ends at one of the given conditions.

    When you use the MY_CORE_ONLY define, please add "hwInit();" into the setup() routine.

    Would you please post the three demo code examples that you tested?


  • Hero Member

    @d00616 said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    add "hwInit();" into the setup() routine.

    OK, I just now did that, but I'm not getting any difference in the results.


  • Hero Member

    In any case, I'm sure the question will ultimately turn from "How do I wake up based on a pin change?" to "How do I wake up based on the LPCOMP output, which has that pin as its input?" The reason: as covered earlier in this thread, much lower current consumption while sleeping if doing it via LPCOMP rather than the more straightforward pin monitoring.


  • Contest Winner

    @NeverDie said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    In any case, I'm sure the question will ultimately turn from "How do I wake up based on a pin change?" to "How do I wake up based on the LPCOMP output, which has that pin as its input?" The reason: as covered earlier in this thread, much lower current consumption while sleeping if doing it via LPCOMP rather than the more straightforward pin monitoring.

    It's a good question about, how to design the API to do this. I have no good idea.
    Until an API, you can set MY_HW_RTC->CC[0] to (MY_HW_RTC->COUNTER+2). This ends sleep with some latency.


  • Hero Member

    This post is deleted!

  • Hero Member

    This post is deleted!

  • Hero Member

    This post is deleted!

  • Hero Member

    Is it just me, or does the myBoardNrf5 cause I2c to fail during initialization? I have code which worked fine on mNrf5Board but which now hangs during initialization when using myBoardNrf5. ๐Ÿ˜ž Is it working for anyone else?


  • Hero Member

    @NeverDie said in ๐Ÿ’ฌ MySensors NRF5 Platform:

    Is it just me, or does the myBoardNrf5 cause I2c to fail during initialization? I have code which worked fine on mNrf5Board but which now hangs during initialization when using myBoardNrf5. ๐Ÿ˜ž Is it working for anyone else?

    I've re-installed everything and am still getting no joy using I2C currently. The non-I2C stuff seems to be working fine though.
    So, before I spin more cycles trying to figure it out, is i2c working for anyone else right now using the latest builds and myBoardNrf5? Or, is I2C currently broken?


 

369
Online

7.8k
Users

8.7k
Topics

93.0k
Posts