Pages: [1]   Go Down
Author Topic: how to ACK and NAK on multi-drop 433MHz network  (Read 1035 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:

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!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 151
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
   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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 151
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh?
Code:
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..
« Last Edit: December 28, 2010, 01:15:09 am by tocpcs » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

exactly what i was after!

thank you so much and happy new year  smiley
Logged

Pages: [1]   Go Up
Jump to: