How to send updated V_TEXT/S_INFO to controller?
-
I'm working on an alarm clock... my controller is Domotiocz. I'm using a text sensor to send the alarm time to my arduino.... the following post helped me get it all working properly -> lcd-clock-and-text-sensor-node-with-new-v_text
My clock also has buttons (like a traditional alarm clock), I've written all the code to change the alarm using the buttons.
Now I want to send the new alarm time set on the arduino to the controller (Domoticz), and have the text sensor updated. I thought this would simply be a send(....) command, but I can't get it working.
Here is a sub-set sample code of what I thought I needed to do to send the update (I'm on mysensors 2.0.*)
#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_NODE_ID 9 #include <SPI.h> #include <MySensors.h> #define cID_ALARM_TIME 1 MyMessage MySensors_MSG_Alarm1_Time(cID_ALARM_TIME, V_TEXT); void setup() { Serial.begin(115200); request(cID_ALARM_TIME, V_TEXT); } void presentation() { sendSketchInfo("WakeUp Clock", "0.0.1"); present(cID_ALARM_TIME, S_INFO, "Alarm Time", true); } void loop() { int newHour = 12; int newMinute = 45; String val = String(newHour) + "." + String(newMinute); send(MySensors_MSG_Alarm1_Time.set(val), true); } void receive(const MyMessage &message) { if (message.type==V_TEXT) { if (message.sensor == cID_ALARM_TIME){ // Here is where the return value comes from Domoticz when requesting the V_TEXT } } }When I run it I get the following console message....
35287 TSF:MSG:SEND,9-9-0-0,s=1,c=1,t=47,pt=1,l=1,sg=0,ft=0,st=OK:1 35297 TSF:MSG:READ,0-0-9,s=1,c=1,t=47,pt=1,l=1,sg=0:1 35302 TSF:MSG:ACKand then my controller (Domoticz) updates the text sensor to the value of 1
I'm very confused, please help :)
-
You should not use the String class in a Arduino environment (google why).
The send function takes a char buffer. If you need to append/copy things into it, use strcpy or memcpy.
-
@mfalkvidd
Sure, if you'd like some more control over things :) -
You should not use the String class in a Arduino environment (google why).
The send function takes a char buffer. If you need to append/copy things into it, use strcpy or memcpy.
@hek
Ok, I think I understand what you are saying, but I can't figure out the implementation.This didn't work
char temp_Msg[3]; strcpy (temp_Msg, char("1")); strcpy (temp_Msg, char(".")); strcpy (temp_Msg, char("1")); send(MySensors_MSG_Alarm1_Time.set(temp_Msg), true);or this
char temp_Msg[3]; strcpy (temp_Msg, "1"); strcpy (temp_Msg, "."); strcpy (temp_Msg, "1"); send(MySensors_MSG_Alarm1_Time.set(temp_Msg), true);or this
char temp_Msg[3]; strcpy (temp_Msg, '1'); strcpy (temp_Msg, '.'); strcpy (temp_Msg, '1'); send(MySensors_MSG_Alarm1_Time.set(temp_Msg), true);But this does work (message is sent and loaded into Domoticz)
send(MySensors_MSG_Alarm1_Time.set("1.1"), true);What am I not understanding?
-
Oh, I didn't know I needed to use both.
Well I tried a million combinations after seemingly reading everything on the subject, and I still couldn't get {int + char + int} converted into a char[] using strcpy and strcat
for some reason my brain is just not wrapping itself around the concept today... maybe I'll come back to it tomorrow.
In the mean time, I tried the following and it worked.
char buf[20]; sprintf(buf, "%d.%d", Alarm1_Time_Local[0], Alarm1_Time_Local[1]); send(MySensors_MSG_Alarm1_Time.set(buf), true);I've read that using sprintf increases the size of your sketch... but for now I'm fine with it, since it works and I can move on to being creative and productive.. lol
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login