I have 6 units on using a 433MHz transceiver being one base station and 5 slave units. The transceivers that i am using are all broadcast i.e. every unit can see the data being sent to and from other units.
Each unit has been given individual names such as BaseStation, Unit1, Unit2 etc...
The base station will poll the units (using strings) and ask for data from Unit1 etc...
Does anyone have any code that supplies an ACK or NAK when successful / unsuccessful strings are received? Its currently doing my headin!
void loop()
{
while (Serial.available())
{
delay(10);
char c = Serial.read();
readString += c;
}
if (readString.length() >0)
{
Serial.println(readString); //prints string to serial port out
if (readString.substring(0) == "START")
{
Serial.println("START detected");
readString=""; //clears variable for new input
Flash();
}
if (readString.substring(0) == "RESET")
{
Serial.println("RESET detected");
readString=""; //clears variable for new input
Reset();
}
readString=""; //clears variable for new input
}
}
this is the code I am currently using.
Also how can i modify this so that it looks for start and end characters such START or RESET.
void setup() {
myName = "2";
}
void loop()
{
while (Serial.available())
{
delay(10);
char c = Serial.read();
readString += c;
}
if (readString.length() >0)
{
//Commenting this out, you don't need to echo it back to everyone.
//Serial.println(readString); //prints string to serial port out
if (readString.substring(1, 2) == myName) { // this if statement gets the unit to check if it's for it.
if (readString.substring(0) == "START")
{
Serial.print("!");
Serial.print(myName);
Serial.println("-START-OK");
readString=""; //clears variable for new input
Flash();
} elseif (readString.substring(0) == "RESET")
{
Serial.print("!");
Serial.print(myName);
Serial.println("RESET-OK");
readString=""; //clears variable for new input
Reset();
} else {
Serial.print("!");
Serial.print(myName);
Serial.println("COMMAND-UNKNOWN");
readString=""; //clears variable for new input
} //end if checking for valid command match
} else {
//do nothing - or something if you need to?
} //end if - command was not for me
}