Receivetime and Request in 1.6
-
Hi!
Im building a sketch in 1.6.0b where im first request time and then request a v_text (code pretty much standard)
requestTime(); request(messageCHILD, V_TEXT, 0);
void receiveTime(unsigned long time) { // Ok, set incoming time Serial.println("requesting time"); setTime(time); timeReceived = true; } // This is called when a message is received void receive(const MyMessage &message) { Serial.print("Msg 2 Child: "); Serial.print(message.sensor); Serial.print(", Message: "); Serial.println(message.getLong()); if (message.sensor == messageCHILD){ if (message.type==V_TEXT) { // Text content temp = message.getLong(); // copy it in newMessageAvailable = true ; } } }
But the text and time as mixed up and i recieve not only my textmessage but also the time in V_TEXT:
Log:
requesting time
read: 0-0-105 s=255,c=3,t=1,pt=0,l=10,sg=0:1450651817
send: 105-105-0-0 s=8,c=2,t=47,pt=0,l=0,sg=0,st=ok:
read: 0-0-105 s=8,c=2,t=47,pt=0,l=2,sg=0:10
Message: 8, Message: 105065181710 is read and its the right value, but the message.getlong is 1050651817
@AWI or anyone?
-
@sundberg84 said:
temp = message.getLong();
I don't understand why you try to get a long-value from the incoming text-message?
You seem to receive a 2 byte string (pt=0) which indicates a string.
https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/core/MyMessage.h#L180If you read a long (4-bytes) you'll probably pick up trash from the previous message.
-
@hek Ok, I was thinkig that it can be a 10.7 as temp as well and i will only send temp values.
What do you suggest i use?
-
Try using msg.getString()
-
Ok, tried that but it doesnt work. Its like the recieve time variable doesnt empty and the first numbers is just overwritten:
read: 0-0-105 s=255,c=3,t=1,pt=0,l=10,sg=0:1451249777
requesting time
send: 105-105-0-0 s=8,c=2,t=47,pt=0,l=0,sg=0,st=ok:
read: 0-0-105 s=8,c=2,t=47,pt=0,l=3,sg=0:5.5
Msg to Child: 8, Message: 5.51249777So the variable with my time is 5.5 and 1249777 from time.