Hi folks, I have learned a lot from reading the posts here Thanks.
This is my first post. I am new to all of this so sorry if my code is terrible and I am making a basic mistake.
I hope this is clear.
I am developing a phone app that communicates with a particle on my home network which then communicates with my home lighting system . It works but need help getting the next stage working
I have my particle sitting on my wifi network used to send messages via tcp client/socket to my lighting system to turn lights on/off or to a dim level. I use a phone app developed in MIT app inventor to call the particle function and pass a string to the particle to decide which light turns on , the particle then in turn sends a string to the lighting system. I just use an if statement and if the value of the string read is = to x then send string eg "^/+A014" to lighting system to turn light no 14 on. "^/+B014" turns light off. etc
This all works fine. Now I want to add a function to the app where I can select the light and the light level via a slider . I have the phone app working and have created and send a string in the correct format. to the particle via function.
eg . "^/+E0148508
E requests dim
014 requests light no 014
85 requests light level 85%
08 requests time to get to level
Now when I try and send this string to my lighting system and nothing. I have created a particle value and send this back to the phone app to check the string is correct and all looks good .but for some reason the format is not being accepted by my lighting system..
client.write("^/+E0108508"); // when this raw string is sent to lighting system it works.
client.write(value1); // value1 =variable sent value1 = "^/+E0108508" it does not work
where value1 = the particle function string = "^/+E0108508"
So what appears to be the same value sent to lighting system doesn't work. I think it has something to do with the format of the string .
I'm not a programmer just trying to figure it out as I go. Thanks in advance.
#include <Adafruit_IO_Particle.h>
TCPClient client;
byte server[] = { 192, 168, 15, 50 }; // connection to lighing system tcp client
String value1 = "will be populated from MIT app inventor"; // local string linked through " Particle.variable("value1",value1);" to MIT app inventor variable value1
void setup()
{
Particle.function("lcontrol",lights); // MitAI function to select individual lights triggered from app buttons
Particle.function("trigger",trigger1); // MitAI function to trigger dim function triggered by slider in MIT app inventor.
Particle.variable("value1",value1); // Value sent back to phone app to confirm string sent to lighing system, sends back string received from app "dim_value".
}
void loop()
{
}
int trigger1(String dim_value) {
if (dim_value != "xxxx") { // if value is not equal X then perform the below.
client.connect(server, 5001); // connect to lighing system.
dim_value = (value1) ; // store received value as "value1"
Particle.publish("value1"); // send string back to MIT app inventor for testing
client.write(value1); // send sting to lighting system. when variable sent it lighting system this does not work.
//client.write("^/+E0108508"); // when this raw string is sent to lighting system it works.
client.flush();
client.stop();
return 1000;
}
else {
return 2000;
}
}