Problems with V_TEXT in MySensors 2.0.0



  • I've been converting my sketches to MySensors 2.0.0, and I seem to have hit a problem with a node using V_TEXT and S_INFO, getting a text value from Domoticz. Previously - under 1.5 - I had added V_TEXT and S_INFO to MyMessage.h, and this worked OK. (I have a text sensor in Domoticz, and typically this has a value such as 10.3#77#3, which I'm parsing in the sketch.)

    Now, however, I cannot get the sketch to read the value.

    I've stripped the sketch down to the bare basics here:

    // Text Sensor
    // MySensors 2.0.0
    
    #define MY_DEBUG
    
    #define MY_RADIO_NRF24
    #define MY_RF24_CE_PIN 7
    #define MY_RF24_CS_PIN 8
    
    #define MY_NODE_ID 40
    
    #include <MySensors.h>
    
    #define SKETCH_NAME "Text sensor"
    #define SKETCH_MAJOR_VER "2.0"
    
    #define TEXT_CHILD_ID 11
    
    unsigned long SLEEP_TIME = 30000;  	//  0.5 min. (300 sec.) sleep time between reads (seconds * 1000 milliseconds)
    String tempSensor;
    String outsideTemp;
    
    MyMessage textMsg(TEXT_CHILD_ID, V_TEXT);
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER);
    
    	present(TEXT_CHILD_ID, S_INFO);
    } 
    
    void setup()  
    {  
    
    }
    
    void loop() 
    {
    	request(TEXT_CHILD_ID, V_TEXT); 
      
    	// Sleep until something happens with the sensor
    	sleep(SLEEP_TIME);
    } 
    
    void receive(const MyMessage &message) {
    	if (message.type == V_TEXT)
    	{
    		tempSensor = message.getString();
    		int sepIndex = tempSensor.indexOf('#');
    		outsideTemp = tempSensor.substring(0, sepIndex);
    		Serial.println(tempSensor);
    	}
    }
    

    The main difference was changing 'void incoming Message' to 'void receive'.

    I've included a sample of the serial output here:

    TSP:MSG:SEND 40-40-0-0 s=11,c=2,t=47,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 40-40-0-0 s=11,c=2,t=47,pt=0,l=0,sg=0,ft=0,st=ok:
    TSP:MSG:SEND 40-40-0-0 s=11,c=2,t=47,pt=0,l=0,sg=0,ft=0,st=ok:
    

    The sketch seems to be sending out empty text strings, but not issuing any reads.

    Any clues? Thanks in anticipation.


  • Hero Member

    @MikeF you are sleeping the node for almost all the time. While sleeping the node won't receive any messages. Use wait() instead.



  • Thanks, @AWI - using wait() instead of sleep() works.

    However, isn't there an issue for battery-powered nodes in using wait rather than sleep? Sleep worked OK on my sketch under MySensors 1.5 - maybe the use of gw.begin(incomingMessage, NODE_ID) woke it up?

    Will this also be the case with other sketches which receive messages from the controller? for example, I have still to convert an RGB LED sketch which gets a hex value (in the form 0xrrggbb) from the controller?


  • Hero Member

    @MikeF Good to hear that it worked for you. Possible just coincidence that it worked in V1.5. Reception of information on battery powered nodes is always an issue. The radio consumes a lot of energy while listening. There are a few new options in V2 to get around that. Take a look at the "Sleeping" section of the API Description


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 1
  • 6
  • 1
  • 10

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts