1.4 Beta


  • Admin

    A major code drop coming from @ToSa has now been merged into 1.4. It contains:

    • The new MySensors Bootloader supporting Over-the-air sketch updates ("client"-side).
    • A simple NodeJs Controller to test the OTA stuff ("server"-side).
    • Changes to cope with new sketch meta data stored in EEPROM and conversion between serial protocol/binary data and some new STREAM command types added.
    • A new internal command has also been added to allow resetting a node remotely.

    A more detailed change log can be found here:
    https://github.com/ToSa27/Arduino/commits/development

    I haven't had time to test myself yet but everything has been verified by @ToSa and is reported working. He is on a business trip right now so advanced bootloader questions have to wait until he's back.


  • Mod

    @hek Sounds like a good step forward!
    Only one boot loader question: does this mean we can use an external boot loader or do we have to use an external boot loader now?


  • Admin

    @marceltrapman

    The OTA stuff is optional. But if you want to be able to hot deploy sketches over the air, you have to install the MySensors bootloader.


  • Code Contributor

    @hek There are still some problem with string termination,

    repeater started, id 3
    send: 3-3-0-0 s=255,c=0,t=18,pt=0,l=15,st=fail:1.4b1 (18848a2)
    send: 3-3-0-0 s=255,c=3,t=6,pt=1,l=1,st=fail:0
    send: 3-3-0-0 s=255,c=3,t=11,pt=0,l=9,st=fail:Relaytest848a2)
    send: 3-3-0-0 s=255,c=3,t=12,pt=0,l=3,st=fail:1.0aytest848a2)
    read: 5-5-0 s=11,c=1,t=1,pt=0,l=4:58.4
    send: 5-3-0-0 s=11,c=1,t=1,pt=0,l=4,st=fail:58.4
    send: 3-3-0-0 s=10,c=1,t=0,pt=0,l=5,st=fail:26.20


  • Code Contributor

    @Damme My bad wrong working directory! sorry


  • Mod

    @hek said:

    • Sleep functions now takes unsigned long. This allows sensor to sleep for than 30 sec 😉

    Thank you 🙂


  • Mod

    @hek said:

    • Corrected string termination

    And thanks again!!!



  • How do I request information from a node from the gateway?

    I have a relayactuator node with 2 relays that is transmitting its initial state at the startup of the node. This is also received by the gw.
    But after that I cant seem to request the current relay status from the node by sending a message from the gateway.

    I tried lots of combinations, nothing worked.

    I thought this would be correct:
    1;2;2;1;2;0\n
    1=node number
    2=sensor (relay number 2)
    2=request
    1=ack message
    2=light
    0=string??

    Can anyone point me in the correct location?
    maybe a new API page for 1.4 would be handy

    edit: also I can't find anywhere what the debug letters mean
    what is s=,c=,t=,pt=,l=,st= ??


  • Admin

    @timminater

    You cannot request state from a node without programming a little . I answered exactly this question a couple of posts back in this thread.

    http://forum.mysensors.org/topic/168/1-4-beta/34



  • @hek
    Could u plz help me
    getting in eth GW. Vera and Libs updated.

    **0;0;3;9;Arduino startup complete.
    0;0;3;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0:
    0;0;3;9;version mismatch0;0;3;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0:
    0;0;3;9;version mismatch0;0;3;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0:
    0;0;3;9;version mismatch0;0;3;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0:
    **


  • Admin

    @mitekg

    All the zeroes indicates that something is wrong in radio communication. Check wires.



    • The new MySensors Bootloader supporting Over-the-air sketch updates ("client"-side).
      • A simple NodeJs Controller to test the OTA stuff ("server"-side).
        Is any instructions, how to use this?
        thx.

  • Code Contributor

    @hek
    I think BASE_RADIO_ID should be declared in MyCofig.h


  • Hero Member

    @hek @ToSa

    Could we get a description of how the OTA programming works?

    (Terminology: the program flash is divided into a bootloader section and an application section; compile sketches go in the application section)

    One approach is to have a separate flash or eeprom chip which one somehow fills (this could even happen at the application level). When booting, check this flash or eeprom and if valid - load into internal program flash, clear the vallidity of the external flash or eeprom (so you won't loop loading it again) and reboot. When you reboot there will be no valid image to copy from external memory, so you jump to the start of internal application flash. This takes external flash as large or larger than application flash (eg: >= 32 KiB for the 328p)

    I think you are taking a different route, where the bootloader is somehow given control, after which it receives nRF packets to RAM, periodically writing another page from RAM to the application section of internal flash. When done, reboot.

    If booting and there is no valid image in external memory and the CRC of the internal application flash section is valid, jump to it as usual.

    I'm not sure if you can also still use serial programming.

    This could be all wrong. It implies keeping (at least part of) the nRF library in bootload program flash, to receive packets. I'm putting it out as a hypotheis to help elicit the real description.

    How big is the OTA bootloader?


  • Admin

    @Damme said:

    I think BASE_RADIO_ID should be declared in MyCofig.h

    Yes, that's a better place for it.


  • Admin

    @Zeph, @mitekg

    Right now the OTA works without any need for external flash. @ToSa will have to answer the details when he's back (like size, building, serial programming).

    Yes it uses a VERY stripped down rf24 library.
    https://github.com/mysensors/Arduino/blob/development/Bootloader/MyOtaBootloaderRF24.h

    Not much of the MySensors library is needed.
    https://github.com/mysensors/Arduino/blob/development/Bootloader/MyOtaBootloader.c



  • I am in process of upgrading to 1.4b1 - have most things working. I noticed that my status consistently fails during setup() when presenting sensors AND also never receive a return message from controller after a time request. It's always the same two failures.

    Everything works after adding a 100ms delay between calls. Not sure if there's a timing problem somewhere.

    Hek - as always thanks for ALL your contributions. 🙂

    Joe K.

    SERIAL CONSOLE OUTPUT:
    sensor started, id 4
    send: 4-4-0-0 s=255,c=0,t=17,pt=0,l=15,st=ok:1.4b1 (18848a2)
    send: 4-4-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    send: 4-4-0-0 s=255,c=3,t=11,pt=0,l=11,st=ok:LCD Display
    send: 4-4-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 4-4-0-0 s=0,c=0,t=7,pt=0,l=15,st=ok:1.4b1 (18848a2)
    send: 4-4-0-0 s=1,c=0,t=6,pt=0,l=15,st=fail:1.4b1 (18848a2)
    send: 4-4-0-0 s=2,c=0,t=8,pt=0,l=15,st=ok:1.4b1 (18848a2)
    send: 4-4-0-0 s=255,c=3,t=1,pt=0,l=15,st=fail:1.4b1 (18848a2)

    CODE in setup():
    // Send the Sketch Version Information to the Gateway
    gw.sendSketchInfo("LCD Display", "1.0");

    // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID_DHT_HUM, S_HUM, true);
    delay(100); // needed otherwise status may come back as failed

    gw.present(CHILD_ID_DHT_TEMP, S_TEMP, true);
    delay(100); // needed otherwise status may come back as failed

    gw.present(CHILD_ID_BMP085_BARO, S_BARO, true);
    delay(100); // needed otherwise status may come back as failed & time request doesn't work

    // request time
    gw.requestTime(receiveTime);


  • Code Contributor

    @hek Does the gateway use any eeprom?


  • Admin

    @Damme

    Yes, it uses eeprom for storing routing information.


  • Code Contributor

    @hek ok, how many bytes does it use?


  • Admin

    @Damme

    If you want to store you own data in EEPROM you can use the provided saveState(), loadState(). It makes sure you won't overwrite anything important. If 256 bytes isn't enough you can start writing at position EEPROM_LOCAL_CONFIG_ADDRESS defined in MySensors.h.


  • Code Contributor

    @hek I just cant figure this out:
    0;0;3;9;read: 255-255-0 s=255,c=3,t=3,pt=0,l=0:
    0;0;3;9;send: 0-0-255-255 s=255,c=3,t=4,pt=0,l=2,st=fail:42
    the last one isn't sent.What have I missed?
    I have also tried 42 as int (no "")

    	msg.destination = 255; 		//NodeID
    	msg.sender = GATEWAY_ADDRESS;
    	msg.sensor = 255;	  				//SensorID
    	msg.type = I_ID_RESPONSE;			//MsgType
    	mSetCommand(msg,C_INTERNAL); 		//Subtype
    	mSetRequestAck(msg,true);			//Request ack
    	mSetAck(msg,false);
    	msg.set("42");					//Payload
    	sendRoute(msg);

  • Mod

    @hek Do you know if the ota is something initiated by the controller or do we update the gateway with a new version and will the gateway be responsible?


  • Admin

    @marceltrapman

    The controller will be responsible for initiating and serving the new sketch version. There is basically no changes in gateway except being able to handle binary data.


  • Admin

    @Damme

    mSetRequestAck(msg,true);

    You should probably not request ack back on a id-response. But I doubt that is the cause for transmission error. What is happening in the sensor node?


  • Code Contributor

    @hek Tried with no ack also. And the node doesn't recieve anything. I'm out of components to build myself a sniffer right now.. Might have to kill something.. 💥 I can recieve From the node though.. but the node does not read from gateway..


  • Admin

    @Damme

    You only live 190 km from me. Come and get some 😄

    What kind of antenna on your gateway? Have you tried lowering transmit power of gateway?


  • Code Contributor

    @hek I fixed the problem , it was the RF24_PA_LEVEL_GW .. needed to be low.

    You are correct with the ack on id-response, it gets all fucked up. Stuck in loop requesting ID 10+times/second. And doesnt register the id.. Too bad. would be really good for me to know if the sensor actually got the id_response or not... (and if it's sent as node 255 or node newid doesnt really matter..)

    edit:
    I changed my aproach to checking if sendRoute(msg) is true. But I still have a problem that the node actually recieves the packagt but just ignored is. sometimes I need to reset the node for it to get accept the new ID.. example;

    0;0;3;9;read: 255-255-0 s=255,c=3,t=3,pt=0,l=0:
    0;0;3;9;send: 0-0-255-255 s=255,c=3,t=4,pt=1,l=1,st=ok:20
    0;0;3;9;read: 255-255-0 s=255,c=3,t=3,pt=0,l=0:
    0;0;3;9;send: 0-0-255-255 s=255,c=3,t=4,pt=1,l=1,st=ok:21
    0;0;3;9;read: 255-255-0 s=255,c=3,t=3,pt=0,l=0:
    0;0;3;9;send: 0-0-255-255 s=255,c=3,t=4,pt=1,l=1,st=ok:22
    0;0;3;9;read: 255-255-0 s=255,c=3,t=3,pt=0,l=0:
    0;0;3;9;send: 0-0-255-255 s=255,c=3,t=4,pt=1,l=1,st=ok:23
    

    I'll try to look at the debug output on the node tomorrow..

    btw: \n missing line 278 mysensor.cpp debug(PSTR("version mismatch"));


  • Mod

    @hek said:

    The controller will be responsible for initiating and serving the new sketch version. There is basically no changes in gateway except being able to handle binary data.

    How do I get this started Henrik?


  • Admin

    @marceltrapman

    Until @ToSa is back, I suggest you have a look at how the NodeJSController serves hex-files.
    https://github.com/mysensors/Arduino/blob/development/NodeJsController/NodeJsController.js


  • Mod

    @hek I wanted to update my MQTT gateway to 1.4beta state but run into a problem with the serial message format.
    If I interpret the code right, the messages sent (in serial message format) to the ethernet gateway (over ethernet, so from my linux system running the MQTT gateway) contain 6 fields, of which the 4th is the ack flag.
    Messages received from the ethernet gateway contain 5 fields, with no ack indication.
    Shouldn't the message format be identical in both directions, as it is for the 1.3 version?


  • Admin

    @Yveaux

    Yes, It might be interesting (for the controller side) to use the 4th field to flag if the received message is an ack or regular message.

    ...so for outgoing you enable receiver to send ack back. And incoming the flag indicates if this as an ack or regular message.

    Make sense?


  • Mod

    @hek said:

    Make sense?

    Makes sense 😉


  • Plugin Developer

    Short question. I'm browsing the 1.4 code and is there a replacement for waitForMessage? I've looked into the code online but can't seem to find it. And if not, is it possible to attach the radio to an interrupt to call an interrupt routine on incoming message?


  • Mod

    @John said:

    is it possible to attach the radio to an interrupt to call an interrupt routine on incoming message

    The last question is a definite yes, see for example https://github.com/Yveaux/NRF24_Sniffer/blob/master/Arduino/NRF24_sniff/NRF24_sniff.ino function handleNrfIrq. Connect the NRF24 IRQ to pin 2 and call attachInterrupt to register the interrup handler.

    Be very careful what you do in this interrupt handler, though. Don't try to receive any message for example, as the SPI access to the NRF24 is not interrupt-proof, as is the MySensors library!


  • Admin

    @John

    Yep, as @Yveaux says, be careful what you do inside interrupt handler.

    Not sure what you try to archive here.. but in 1.4 you should usually just call process() in your loop(). The callback you registered a in begin(callback) will be called on incoming messages.

    See RelayActuator for an example.


  • Plugin Developer

    @Yveaux

    Be very careful what you do in this interrupt handler, though. Don't try to receive any message for example, as the SPI access to the NRF24 is not interrupt-proof, as is the MySensors library!

    Darn, i hoped it could.

    @hek

    Not sure what you try to archive here.. but in 1.4 you should usually just call process() in your loop(). The callback you registered a in begin(callback) will be called on incoming messages.

    I'm averaging sensor results, so i read sensors every second an send them every minute, also this setup has an 16x2 display attached to show the values. But i would like it to be bi-directional with the server so it can display the server send data. Thus if i would use waitForMessage i can let it wait about a second for a message read sensor values, and let it wait for a second again. (because i understood it blocks?)


  • Mod

    @John You can obtain the same result as the old waitForMessage by registering a callback. Have this callback set a flag and call process() in the loop, as hek suggests.
    You could also turn things around and read and average your sensors from a (timer)interrupt handler.
    But when you're not completely confident with using interrupts then its better to avoid them and just process everything from your loop(). Interrupts can introduce lots of nasty problems if you don't know exactly what you're doing!


  • Plugin Developer

    @Yveaux

    You can obtain the same result as the old waitForMessage by registering a callback. Have this callback set a flag and call process() in the loop, as hek suggests.

    Well, that was my first try and hoped it was interrupt based because of one wire connected on arduino pin 2 to IRQ on the NRF. The reason i asked it because i saw an example from an other library: http://maniacbug.github.io/RF24/pingpair_irq_8pde-example.html .

    You could also turn things around and read and average your sensors from a (timer)interrupt handler.

    I will have to investigate if any of the components is using which timer and what will be influenced by it. I'm using an HD44780 alike as display so i'm not sure because never dived deep into the used library.

    But when you're not completely confident

    about 90%?

    @hek
    It would be nice if a waitForMessage like functionality would be included in 1.4.


  • Hero Member

    @hek Any idea when 1.4 will become the production version?


  • Admin

    @clippermiami

    We're still making small changes in the protocol and serial API which we need to stabilize before release.
    I also need time to update the main site to reflect the new version before its "released" .


  • Admin

    Added few small changes:

    • Add dimmable LED actuator example (converted @blacey 1.3 example)
    • Rename PING to the more suitable FIND_PARENT
    • Float values sent in binary format over the air
    • Move base-radio-id to MyConfig.h

    https://github.com/mysensors/Arduino/commits/development


  • Code Contributor

    @hek another suggestion for addition

    RelayWithButtonActuator
    incomingMessage should check if there is any payload or not. (could be bad package)
    I use empty payload as a request for latest state (Yes I could do this some other way but I think it is logical..)

      if (msg.type==V_LIGHT && strlen(msg.getString())!=0) {

  • Plugin Developer

    Because of the use of custom variables and the possibility of receiving and sending and of many sensor type possibilities is it possible to add a "sensor" type of S_OTHER (or alike)? I think this then would be in line of having var types V_VAR1, etc.. of which then would be something else then defined.

    This will add the possibility to send other then sensor related data. This is of course possible but could semantic wise be more applicable.


  • Admin

    @John

    Yes


  • Admin

    A small serial protocol breaking change was just checked in. @John and @marceltrapman you might want to have a look at this.

    Serial protocol changed to allowing controller to know if an incoming message is an ack. Outgoing and incoming serial messages now also have the same parameter count.

    radioId;childId;messageType;ack;subType;payload\n
    

    Where ack parameter means the following:
    outgoing: 0 = unacknowledged message, 1 = request ack from destination node
    Incoming: 0 = normal message, 1 = this is an ack message

    (previously only outging messages had the ack-flag)


  • Plugin Developer

    @hek

    Thanks for the heads up. This will give a good way of tracking messages send controller wise. I can take a look at it tomorrow evening if you would like a third party ack this works ok.


  • Mod

    @hek Thanks for the quick response!


  • Code Contributor


  • Plugin Developer

    @hek I have a couple of questions:

    Have not tested it yet, but that now ack's are possible i would like to implement a retry queue next to a normal send queue. The questions then would be:

    • How long does it take for the longest possible message to be send?
    • Is there a delay needed between each send?
    • Is there an ack timeout?

    John.


  • Mod

    @Damme Yeah, so header changed again... Madness 👊
    I'll have to update the dissector then...


  • Admin

    @John

    The send time depends on how many hops the message need to make. But on the controller side you could perhaps wait for a couple of second before trying again.

    There is no ack timeout but each hop on the way to the destination will only be tried once (using the build in retry functionality of the nrf-chip).



  • @hek Any tips on upgrading the June 1.4b1 to the August 1.4b1. I just attempted it with disastrous results. 🙂

    I started off.

    1. Uploading the Vera files
    2. Re-compiled the new gateway (after changing the my IP Address and such)
    3. 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.

    1. Do all the sensors have to be updated at once?
    2. Will existing sensors under the June 1.4b1 build co-exist with the August 1.4b1 Gateway build?
    3. Can we just recompile our existing June sketches under the new mySensors library as long as no compile errors show?

    Thanks


  • Admin

    @lininger

    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..


  • Mod

    @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...


  • Admin

    @Yveaux

    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?


  • Mod

    @hek said:

    Do you have any suggestion?

    It's in my post hek 😉


  • Mod

    @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?


  • Admin

    @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.


  • Mod

    @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.


  • Admin

    @Yveaux

    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).


  • Code Contributor

    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?


  • Admin

    @Damme

    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;1

    You can see my Node-Red output below:
    Schermafdruk 2014-08-20 20.25.29.png

    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?


  • Admin

    @warawara

    Did you remember sending a newline?



  • @hek
    Yes I did.

    My Node-Red is configured to send a newline after every command.

    But just to make sure I also tried adding it to the string.

    Same result.



  • @hek

    I assume sending de command in ascii is good or do I need to send a binary buffer?


  • Admin

    @warawara

    If it's working from your gateway Serial Monitor in IDE you must be doing something wrong in your program.



  • @hek
    Not working in IDE.



  • @hek

    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.


  • Code Contributor

    @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..



  • @Damme
    Thanks for the tip.

    I will try that in the future. But I don't think it was a problem of not receiving on the sensor part. I think it was a problem with not sending on the Serial Gateway part.

    But I got it working now!


  • Hero Member

    Ok, So I took the plunge and upgraded to 1.4.b1, and everything went "OK" with one glaring exception...... All temperatures display in Celsius. No matter what I do, I can't seem to get it to display in Fahrenheit..

    Any Idea's?



  • @hek
    I'd like to ask for a small change to be made to the sleep function.

    When we call gw.sleep(x) or gw.sleep(x,y,z) then the arduino disables the interrupt timer (to save power) that triggers the counter that drives millis(). So the value returned from millis() stalls when we sleep.

    This is ok on our battery powered devices, since it's saving power, but makes it hard to determine how long it's been since we sent values to the gateway.

    For example, if I use this code:

    if ((unsigned long)(millis() - timeOfLastSensorSend) >= MIN_SAMPLING_INTERVAL) {
        // read sensors and send to gateway
        timeOfLastSensorSend = millis();
    }
    gw.sleep(SLEEP_TIME);
    

    Then it doesn't work because millis() does not increment while the the sketch is asleep.

    I have a thought on how we can solve this but I have a to get to a work meeting.



  • Ok, back from meeting.

    So, for sketches that don't need to sleep on interrupt, then things are ok because I can code around it like this:

    if ((unsigned long)(millis() - timeOfLastSensorSend) >= MIN_SAMPLING_INTERVAL) {
        // read sensors and send to gateway
        timeOfLastSensorSend = millis();
    }
    gw.sleep(SLEEP_TIME);
    timeOfLastSensorSend -= SLEEP_TIME;
    

    My rationale here is that if millis doesn't increment then I should make my variable decrement by the same amount. Same effect.

    However, the catch is when sleeping with interrupt. My thinking was to modify MySensors.cpp to change the return value of sleep. Something like this:

    unsigned long MySensor::internalSleep(unsigned long ms) {
        unsigned long origMs = ms;
        while (continueTimer && ms >= 8000) { LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000; }
        if (continueTimer && ms >= 4000)    { LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000; }
        ...
        if (continueTimer && ms >= 16)      { LowPower.powerDown(SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15; }
        return (origMs - ms);
    }
    
    unsigned long MySensor::sleep(unsigned long ms) {
        // Let serial prints finish (debug, log etc)
        Serial.flush();
        RF24::powerDown();
        continueTimer = true;
        return internalSleep(ms);
    }
    
    unsigned long MySensor::sleep(int interrupt, int mode, unsigned long  ms) {
        // Let serial prints finish (debug, log etc)
        unsigned long sleptFor = 0;
        Serial.flush();
        RF24::powerDown();
        attachInterrupt(interrupt, wakeUp, mode); //Interrupt on pin 3 for any change in solar power
        if (ms>0) {
                continueTimer = true;
                sleptFor = sleep(ms);
        } else {
                Serial.flush();
                LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
        }
        detachInterrupt(interrupt);
        return sleptFor;
    }
    

    So rather than return a boolean on sleep(x,y,z), return the amount of time it slept for before it was interrupted. The check of the boolean is replaced with a check if return code > 0.

    Hopefully my ramblings make some kind of sense.


  • Admin

    @ServiceXp

    The sensor fetches the unit setting from Vera at startup. Something probably fails during this data exchange. You'll have to look at the debug logs to see what happens.

    This behavior might change in 1.4 with sensors just reporting SI-units and controller makes the necessary conversion/scaling.


  • Hero Member

    @hek
    This is the first time I've ssh into vera, so I have no idea what I'm looking for.. I have 2 Everspring ST-814's that display correctly, and of course 2 MySensor sensor which did in 1.3, but not in 1.4b1.

    I found this, but not sure if this is what you need.

    02 08/22/14 7:47:04.914 luup_log:87: Arduino: Incoming internal command '0;0;3;9;read: 2-2-0 s=1,c=1,t=0,pt=7,l=5:22.6' discarded for child: nil <0x2f8b3680>
    50 08/22/14 7:47:04.916 luup_log:87: Arduino: Set variable: 2;1;1;0;0;22.6 <0x2f8b3680>
    50 08/22/14 7:47:04.916 luup_log:87: Arduino: Setting variable 'CurrentTemperature' to value '22.6' <0x2f8b3680>
    50 08/22/14 7:47:04.916 luup_log:87: Arduino: urn:upnp-org:serviceId:TemperatureSensor1,CurrentTemperature, 22.6, 92 <0x2f8b3680>
    06 08/22/14 7:47:04.917 Device_Variable::m_szValue_set device: 92 service: urn:upnp-org:serviceId:TemperatureSensor1 variable: CurrentTemperature was: 22.5 now: 22.6 #hooks: 3 upnp: 0 v:0xda4620/NONE duplicate:0 <0x2f8b3680>
    01 08/22/14 7:47:04.918 LuaInterface::CallFunction_Variable func: w_switch Device_Variable 92 urn:upnp-org:serviceId:TemperatureSensor1:CurrentTemperature failed [string "..."]:14: bad argument #1 to 'sub' (string expected, got nil) <0x2f8b3680>
    01 08/22/14 7:47:04.919 LuaInterface::CallFunction_Variable func: w_switch Device_Variable 92 urn:upnp-org:serviceId:TemperatureSensor1:CurrentTemperature failed [string "..."]:14: bad argument #1 to 'sub' (string expected, got nil) <0x2f8b3680>


  • Admin

    @ServiceXp

    The node will be transferring celsius data until it manage to receive settings from controller (this is done in the background) by setup().
    Attach your failing sensor to the computer. Upload sketch with debug enabled. And look at the Serial monitor. Restart a sensor a few times .


  • Hero Member

    @hek

    Thanks, I'll do that when I get home later. Just so I'm clear..

    To enable debugging: I Remove the "//" before the #define DEBUG ** in and ONLY in** the /libraries/MySensors/Config.h file ? Then upload the sketch again to the sensors? (I don't have to upload the gateway sketch also do I?)


  • Admin

    @ServiceXp

    Yes correct!


  • Hero Member

    @hek

    I can only find MyConfig.h file, and DEBUG was already without the "//".

    So I noticed something VERY strange. It seems when I have the sensors connected to the computer, they start reading in Fahrenheit, and once I pull the USB cable it reverts back to Celsius with-in 30-60 seconds..


  • Hero Member

    Yep, I have no idea how to debug this. The debug window reads in Fahrenheit, (and in Vera), but 30-60 seconds after I disconnect the usb cable from my computer (at which point I can't use the serial com window) it reverts back to Celsius.

    I've deleted one of the sensor nodes and child from Vera, cleared the eEPROM and re-install sketch and re-incuded back into Vera...

    I just don't understand why it works while connected to my computer...


  • Admin

    @ServiceXp

    No, this seems strange. The unit settings should get stored in eeprom.


  • Hero Member

    @hek

    Do you think I can rule out my sensor hardware as it works with 1.3? Is there any way I can determine if it's being written to eEPROM while connected to the computer and then after it's disconnected (to see if it's getting overwritten)?


  • Admin

    @ServiceXp

    Do you call process() in loop()?

    But, really.. Don't put too much effort into this. Just hardcode sensor to send fahrenheit until conversion is done by controller plugin.


  • Hero Member

    @hek
    I'm using the boiler plate sketch provided in the 1.4b1 files. The only modifications I've done is add battery code. (Copy and Paste).

    How to I hard code sensor to send in Fahrenheit?

    Sorry you have to hold my hand through this, I'm very new at this.....


  • Admin

    @ServiceXp

    Change

    float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
    

    To

    float temperature = static_cast<float>(static_cast<int>((sensors.getTempFByIndex(i)) * 10.)) / 10.;
    

    But I still wonder what goes wrong...


  • Hero Member

    @hek

    Worked perfectly for the temperature sensor, but it appears the Humidity and Temp. Sketch handles this differently. Not sure what to replace and where.


  • Hero Member

    Not very nice but I think this will work..

      //float temperature = dht.getTemperature();
     float temperature = dht.getTemperature()*9/5 + 32;
      
     if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT");
     } else if (temperature != lastTemp) {
     lastTemp = temperature;
       if (!metric) {
      temperature = dht.getTemperature()*9/5 + 32;   //dht.toFahrenheit(temperature);
     }

 

342
Online

8.9k
Users

9.6k
Topics

101.0k
Posts