Go Down

Topic: how to ACK and NAK on multi-drop 433MHz network (Read 1 time) previous topic - next topic

pate60

Hi there,

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!

pate60

Code: [Select]


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*.

thanks for your help in advance!

tocpcs

In your code, I can't see how you address the devices?

How does each client know the request is for them?

As to your requirement, that seems easy enough:
Code: [Select]
   if (readString.substring(0) == "START")
   {
     Serial.println("START detected");
     readString=""; //clears variable for new input
     Flash();
   } elseif (readString.substring(0) == "RESET")
   {
     Serial.println("RESET detected");
     readString=""; //clears variable for new input
     Reset();
   } else {
         Serial.println("Not understood!");
         readString="";
         Reset();
   }


Though if you send Not understood all devices would receive it - so they all need to make sure they ignore requests that aren't for them.

let's assume you want to reset device 5 of 6.

BaseStation sends out #5RESET
Your code should check for and remove #5, and then move to Reset.
If it isn't #5 it should ignore it.

In it's reply, you could do !5RESET-OK

This would let your BaseStation know #5 reset was OK.

pate60

you're right!

I haven't started the code to address each unit individually yet or phrase it, i understand how it would work just not how to code it.

tocpcs

#4
Dec 28, 2010, 07:14 am Last Edit: Dec 28, 2010, 07:15 am by tocpcs Reason: 1
Oh?
Code: [Select]

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
}


Let me know if this is what you are aiming for..

pate60

exactly what i was after!

thank you so much and happy new year  :)

Go Up