1.4 Beta
-
The 1.4 version of the MySenors Arduino library is new open for beta testing.
Arduino library and examples
https://github.com/mysensors/Arduino/tree/developmentVera plugin (1.4)
https://github.com/mysensors/Vera/tree/developmentHere are some of the hi-lights.
- Improved communication reliability (now uses hardware acks and resend functionality).
- Simplified sketches (only one include needed).
- Most common sleep scenarios build in.
- Helper for permanently storing values in the Arduinos EEPROM.
- Acknowledgments can now be requested from gateway and other sensors in network.
- Smaller footprint.
- The message structure has been adopted to work better on RPi platform.
- Binary payloads supported and used for integers between sensors.
- Configuration message (only metric setting in it today).
- Allow static parent (no dynamic lookups)
- Callbacks for incoming messages and time. No synchronous waiting methods any more -> no missed messages.
All examples in the development branch above has been converted to use the new functionality of the library.
The new API:
/** * Constructor * * Creates a new instance of Sensor class. * * @param _cepin The pin attached to RF24 Chip Enable on the RF module (defualt 9) * @param _cspin The pin attached to RF24 Chip Select (default 10) */ MySensor(uint8_t _cepin=9, uint8_t _cspin=10); /** * Begin operation of the MySensors library * * Call this in setup(), before calling any other sensor net library methods. * @param incomingMessageCallback Callback function for incoming messages from other nodes or controller and request responses. Default is NULL. * @param nodeId The unique id (1-254) for this sensor. Default is AUTO(255) which means sensor tries to fetch an id from controller. * @param repeaterMode Activate repeater mode. This node will forward messages to other nodes in the radio network. Make sure to call process() regularly. Default in false * @param parentNodeId Use this to force node to always communicate with a certain parent node. Default is AUTO which means node automatically tries to find a parent. * @param paLevel Radio PA Level for this sensor. Default RF24_PA_MAX * @param channel Radio channel. Default is channel 76 * @param dataRate Radio transmission speed. Default RF24_1MBPS */ void begin(void (* msgCallback)(const MyMessage &)=NULL, uint8_t nodeId=AUTO, boolean repeaterMode=false, uint8_t parentNodeId=AUTO, rf24_pa_dbm_e paLevel=RF24_PA_LEVEL, uint8_t channel=RF24_CHANNEL, rf24_datarate_e dataRate=RF24_DATARATE); /** * Return the nodes nodeId. */ uint8_t getNodeId(); /** * Each node must present all attached sensors before any values can be handled correctly by the controller. * It is usually good to present all attached sensors after power-up in setup(). * * @param sensorId Select a unique sensor id for this sensor. Choose a number between 0-254. * @param sensorType The sensor type. See sensor typedef in MyMessage.h. * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack. */ void present(uint8_t sensorId, uint8_t sensorType, bool ack=false); /** * Sends sketch meta information to the gateway. Not mandatory but a nice thing to do. * @param name String containing a short Sketch name or NULL if not applicable * @param version String containing a short Sketch version or NULL if not applicable * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack. * */ void sendSketchInfo(const char *name, const char *version, bool ack=false); /** * Sends a message to gateway or one of the other nodes in the radio network * * @param msg Message to send * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack. * @return true Returns true if message reached the first stop on its way to destination. */ bool send(MyMessage &msg, bool ack=false); /** * Send this nodes battery level to gateway. * @param level Level between 0-100(%) * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack. * */ void sendBatteryLevel(uint8_t level, bool ack=false); /** * Requests a value from gateway or some other sensor in the radio network. * Make sure to add callback-method in begin-method to handle request responses. * * @param childSensorId The unique child id for the different sensors connected to this Arduino. 0-254. * @param variableType The variableType to fetch * @param destination The nodeId of other node in radio network. Default is gateway */ void request(uint8_t childSensorId, uint8_t variableType, uint8_t destination=GATEWAY_ADDRESS); /** * Requests time from controller. Answer will be delivered to callback. * * @param callback for time request. Incoming argument is seconds since 1970. */ void requestTime(void (* timeCallback)(unsigned long)); /** * Processes incoming messages to this node. If this is a relaying node it will * Returns true if there is a message addressed for this node just was received. * Use callback to handle incoming messages. */ boolean process(); /** * Returns the most recent node configuration received from controller */ ControllerConfig getConfig(); /** * Save a state (in local EEPROM). Good for actuators to "remember" state between * power cycles. * * You have 256 bytes to play with. Note that there is a limitation on the number * of writes the EEPROM can handle (~100 000 cycles). * * @param pos The position to store value in (0-255) * @param Value to store in position */ void saveState(uint8_t pos, uint8_t value); /** * Load a state (from local EEPROM). * * @param pos The position to fetch value from (0-255) * @return Value to store in position */ uint8_t loadState(uint8_t pos); /** * Returns the last received message */ MyMessage& getLastMessage(void); /** * Sleep (PowerDownMode) the Arduino and radio. Wake up on timer. * @param ms Number of milliseconds to sleep. */ void sleep(int ms); /** * Sleep (PowerDownMode) the Arduino and radio. Wake up on timer or pin change. * See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin * is assigned to what interrupt. On Nano/Pro Mini: 0=Pin2, 1=Pin3 * @param interrupt Interrupt that should trigger the wakeup * @param mode RISING, FALLING, CHANGE * @param ms Number of milliseconds to sleep or 0 to sleep forever * @return true if wake up was triggered by pin change and false means timer woke it up. */ bool sleep(int interrupt, int mode, int ms=0); /** * getInternalTemp * * Read temp from internal (ATMEGA328 only) temperature sensor. This reading is very * inaccurate so we round the result to full degrees celsius. * http://playground.arduino.cc/Main/InternalTemperatureSensor * * @return Temperature in full degrees Celsius. */ int getInternalTemp(void);###To convert an old 1.3 sketch follow this guide:
Include section
Remove the following includes
#include <Sleep_n0m1.h>
#include <EEPROM.h>
#include <RF24.h>
#include <Sensor.h>
#include <Relay.h>Add
#include <MySensor.h>Global variable scope
Change the following lines
Sensor gw; or Relay gw;To
MySensor gw;Also message containers for outgoing messages. E.g. Light level message for child sensor id 1.
MyMessage msg(1, V_LIGHT_LEVEL);####Setup()
In setup() replace sendPresentation with present.
Also note that begin() now allows you to add an function-argument to get callbacks for incoming messages (actuators). begin also controls wether this node should act as an repeater node. See above for full argument list.####Loop()
The sending of values looks a bit different. The old sketches could look like this:
gw.sendVariable(CHILD_ID_LIGHT, V_LIGHT_LEVEL, lux);In new code you send a value by using the MyMessage contaner defined in global scope. Fill it with the value to send like this (where lux is light level in this case).
gw.send(msg.set(lux));Replace any sleeping with the new build in sleep functions. The old code might have a few lines like this:
delay(500); gw.powerDown(); sleep.pwrDownMode(); //set sleep mode sleep.sleepDelay(SLEEP_TIME * 1000);Replace those with:
gw.sleep(<sleep time in milliseconds>);@hek Any tips on upgrading the June 1.4b1 to the August 1.4b1. I just attempted it with disastrous results. :)
I started off.
- Uploading the Vera files
- Re-compiled the new gateway (after changing the my IP Address and such)
- Re-complied the Repeaters
Just to get going. Both repeaters failed at startup with the standard FAIL in the debug logs. Wiping the Eeprom and trying again did not work. Dropping the repeaters for vera and re-including did not work? Finally went back to the June build and restored the vera from last night and then two other units failed to come back online. Had to replace the antennas on those two units to get them back on-line – BIZARRE.
- Do all the sensors have to be updated at once?
- Will existing sensors under the June 1.4b1 build co-exist with the August 1.4b1 Gateway build?
- Can we just recompile our existing June sketches under the new mySensors library as long as no compile errors show?
Thanks
-
@hek Any tips on upgrading the June 1.4b1 to the August 1.4b1. I just attempted it with disastrous results. :)
I started off.
- Uploading the Vera files
- Re-compiled the new gateway (after changing the my IP Address and such)
- Re-complied the Repeaters
Just to get going. Both repeaters failed at startup with the standard FAIL in the debug logs. Wiping the Eeprom and trying again did not work. Dropping the repeaters for vera and re-including did not work? Finally went back to the June build and restored the vera from last night and then two other units failed to come back online. Had to replace the antennas on those two units to get them back on-line – BIZARRE.
- Do all the sensors have to be updated at once?
- Will existing sensors under the June 1.4b1 build co-exist with the August 1.4b1 Gateway build?
- Can we just recompile our existing June sketches under the new mySensors library as long as no compile errors show?
Thanks
Yes, you'll have to recompile/update them all as message format has changed. No need for wiping eeprom or re-include sensors. Also update Vera plugin.
Replacing antenna should not be necessary and I don't understand why that would change anything..
-
Yes, you'll have to recompile/update them all as message format has changed. No need for wiping eeprom or re-include sensors. Also update Vera plugin.
Replacing antenna should not be necessary and I don't understand why that would change anything..
@hek I had a look at the latest state of the 1.4 header format and saw the sender/last/destination have moved to the front position.
This means the protocol version is, once again, located at a different position w.r.t. 1.3 and earlier 1.4 version.
For software trying to interpret any MySensors message (e.g. my sniffer or a (future) MySensors version supporting different protocol versions) or software that checks the library version to match with its own version it becomes nearly impossible to detect which library version a message was sent with.
I propose to start any message, now and in the future, with a protocol version (use a full byte or use some remaining bits for protocol independent data) and stick to that. This makes life for sugested applications a lot easier.
Adding a version which has a different offset every time makes no sense... -
@hek I had a look at the latest state of the 1.4 header format and saw the sender/last/destination have moved to the front position.
This means the protocol version is, once again, located at a different position w.r.t. 1.3 and earlier 1.4 version.
For software trying to interpret any MySensors message (e.g. my sniffer or a (future) MySensors version supporting different protocol versions) or software that checks the library version to match with its own version it becomes nearly impossible to detect which library version a message was sent with.
I propose to start any message, now and in the future, with a protocol version (use a full byte or use some remaining bits for protocol independent data) and stick to that. This makes life for sugested applications a lot easier.
Adding a version which has a different offset every time makes no sense...Sorry.. the sniffer slipped my mind. The purpose was to prepare for future encryption (keeping the changing "last"-field first) and potential split of the routing information and payload. Which would be necessary for supporting other transportation layers (like RadioHead). They might not be interested in any MySensors version-specifics first in the radio message.
Do you have any suggestion?
-
Sorry.. the sniffer slipped my mind. The purpose was to prepare for future encryption (keeping the changing "last"-field first) and potential split of the routing information and payload. Which would be necessary for supporting other transportation layers (like RadioHead). They might not be interested in any MySensors version-specifics first in the radio message.
Do you have any suggestion?
-
@hek I have another question: when sending from a sensor to a gateway the data can have all kinds of formats (text, byte, float etc) which comes out the gateway through the serial protocol. When sending the other way, I guess the serial data is always sent as text by the gateway to the sensor, right?
Too bad we can't also use different formats when sending through the serial api... Did you think about this? -
@Yveaux said:
It's in my post hek
Yes, you suggest to always have but that might not be possible if we choose some other transportation layer (which most probably will use the first bytes for it's own routing).
When sending the other way, I guess the serial data is always sent as text by the gateway to the sensor, right?
Too bad we can't also use different formats when sending through the serial api... Did you think about this?Yes, I've thought about it. We have a couple of options here. Start type:ing variables through the serial protocol (controller must send datatype) or have a hard coded variable->type map on arduino side. Both of these are valid options.
A binary serial protocol is also an option (could be an option when building gateway).. But that makes it harder to debug e.g. Arduino Serial Monitor. -
@Yveaux said:
It's in my post hek
Yes, you suggest to always have but that might not be possible if we choose some other transportation layer (which most probably will use the first bytes for it's own routing).
When sending the other way, I guess the serial data is always sent as text by the gateway to the sensor, right?
Too bad we can't also use different formats when sending through the serial api... Did you think about this?Yes, I've thought about it. We have a couple of options here. Start type:ing variables through the serial protocol (controller must send datatype) or have a hard coded variable->type map on arduino side. Both of these are valid options.
A binary serial protocol is also an option (could be an option when building gateway).. But that makes it harder to debug e.g. Arduino Serial Monitor.@hek said:
but that might not be possible if we choose some other transportation layer
Then the transportation layer data is not part of mysensors protocol. It's that simple!
IMHO This again boils down to nested protocol headers which we talked about before.
The routing info is part of transportation layer (it could even have its own version info) followed by the mysensors header ( starting with a version number) which tells us what's in the message. Then come the actual data, be it a value, presentation info or whatever. I can make a sketch of this structure if that helps in the discussion. -
@hek said:
but that might not be possible if we choose some other transportation layer
Then the transportation layer data is not part of mysensors protocol. It's that simple!
IMHO This again boils down to nested protocol headers which we talked about before.
The routing info is part of transportation layer (it could even have its own version info) followed by the mysensors header ( starting with a version number) which tells us what's in the message. Then come the actual data, be it a value, presentation info or whatever. I can make a sketch of this structure if that helps in the discussion.I think we agree. Only problem is that I haven't split up the structure in mysensors-transportation/mysensors-header/mysensors-payload yet but if you look from the sniffer side this would not matter.
Please post you suggested structure (but in a new thread).
-
I think we agree. Only problem is that I haven't split up the structure in mysensors-transportation/mysensors-header/mysensors-payload yet but if you look from the sniffer side this would not matter.
Please post you suggested structure (but in a new thread).
I got this question from a friend and since I dont know the answer either;
I'm trying to figure out the sleep mode and if the radio module wakes up or not (via INT pin 2) .. but for me it does not seam to do this. Which sleep-modes does 1.4b have and how do I see if the message is for me, and if not continue sleep?
-
I got this question from a friend and since I dont know the answer either;
I'm trying to figure out the sleep mode and if the radio module wakes up or not (via INT pin 2) .. but for me it does not seam to do this. Which sleep-modes does 1.4b have and how do I see if the message is for me, and if not continue sleep?
The radio interrupts is not used at the moment.
It uses the following sleep modes
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);or
LowPower.powerDown(SLEEP_XXXXS, ADC_OFF, BOD_OFF);Depending on if you want timer to wake up or not. Radio is always put to sleep.
For more details, check out MySensor.cpp. -
I'm trying to create my own controller in Node-Red.
My setup is as followed:
Motion Sensor arduino with standard example sketch <--> SerialGateway arduino with standard example sketch <--> USB <--> Node-Red (installed on Raspberry PI)My SerialGateway receives the request for a node ID (255;255;3;0;3;)
I then return a serial command: 255;255;3;0;4;1You can see my Node-Red output below:

For some reason my SerialGateway is not broadcasting my command. It's only repeating the above commands sevral times;
Am i using the correct protocol values or is there something else I should do?
-
I'm trying to create my own controller in Node-Red.
My setup is as followed:
Motion Sensor arduino with standard example sketch <--> SerialGateway arduino with standard example sketch <--> USB <--> Node-Red (installed on Raspberry PI)My SerialGateway receives the request for a node ID (255;255;3;0;3;)
I then return a serial command: 255;255;3;0;4;1You can see my Node-Red output below:

For some reason my SerialGateway is not broadcasting my command. It's only repeating the above commands sevral times;
Am i using the correct protocol values or is there something else I should do?
-
If it's working from your gateway Serial Monitor in IDE you must be doing something wrong in your program.
-
If it's working from your gateway Serial Monitor in IDE you must be doing something wrong in your program.
Got it working, but my solution is not very satisfying.
I swapt the sketches on my 2 arduino's.
Original arduino setup was:
SerialGatway - Arduino pro mini 3.3v (including Decoupling-Capacitor)
Motion Sensor - Arduino Uno (including Decoupling-Capacitor)Now the sketches are switched and it works.
Eventually I will be working with only Arduino pro mini's but still the original setup should have worked.
-
Got it working, but my solution is not very satisfying.
I swapt the sketches on my 2 arduino's.
Original arduino setup was:
SerialGatway - Arduino pro mini 3.3v (including Decoupling-Capacitor)
Motion Sensor - Arduino Uno (including Decoupling-Capacitor)Now the sketches are switched and it works.
Eventually I will be working with only Arduino pro mini's but still the original setup should have worked.
-
@warawara did you try clearing using clear eeprom? That helped me some times. Dont really know why some nodes just wont want to recieve packages..