State control - using commands sent over XBee wireless?
hey everyone.
i have project that's been going along quite nicely... until now. have clock hooked motion sensor, after 15 minutes send motion data wirelessly hub, have hooked via ethernet database. unfortunately me, cannot rid of middle 'wireless gap' step, , problem revolves around it. need come deliniated series of 'states' 2 arduinos go between, , i'm having trouble setting up.
my setup:
clock & motion sensor -> arduino 1 ('clock') <--> xbee 1 ----wireless---- xbee 2 <--> arduino 2 ('hub') -> ethernet -> database.
here's basic diagram of flow of i'm trying do:
(sorry, huge picture, didn't want embed here.)
http://i.imgur.com/ktzrhsj.jpg
so basically:
1 - both enter 'setup', , have wait "ready" signal continue.
2 - 'hub' fetches current time, , sends 'clock', waiting.
3 - once clock's time set, watches 15 minutes, , collects data.
4 - @ end of period, packages up, , sends 'hub'
5 - 'hub' sends data on database, , returns fetch current time (just in case clock off.)
6 - return step #2.
and finally, here's current 'outline' code both.
clock:
and
hub:
now isn't - have entirety of "meat" of programs written in file, everything's running simultaneously, want put framework , more control on everything. aaaand i'm stuck. nothing seems work. i'm not coming clean enough way switch between 'reading' , 'sending', , xbees either getting nothing @ all, or compounding message last thing received , going sort of feedback loop.
any advice @ how control system better wonderful. unfortunately obvious 1 (change hardware!) isn't going happen. gotta work i've got. however, hardware (at least @ moment!) set correctly - xbees sending , receiving perfectly, if load simple programs. problem code.
i have project that's been going along quite nicely... until now. have clock hooked motion sensor, after 15 minutes send motion data wirelessly hub, have hooked via ethernet database. unfortunately me, cannot rid of middle 'wireless gap' step, , problem revolves around it. need come deliniated series of 'states' 2 arduinos go between, , i'm having trouble setting up.
my setup:
clock & motion sensor -> arduino 1 ('clock') <--> xbee 1 ----wireless---- xbee 2 <--> arduino 2 ('hub') -> ethernet -> database.
here's basic diagram of flow of i'm trying do:
(sorry, huge picture, didn't want embed here.)
http://i.imgur.com/ktzrhsj.jpg
so basically:
1 - both enter 'setup', , have wait "ready" signal continue.
2 - 'hub' fetches current time, , sends 'clock', waiting.
3 - once clock's time set, watches 15 minutes, , collects data.
4 - @ end of period, packages up, , sends 'hub'
5 - 'hub' sends data on database, , returns fetch current time (just in case clock off.)
6 - return step #2.
and finally, here's current 'outline' code both.
clock:
code: [select]
#define xbee_id 1
int check = 0;
void setup() {
serial.begin(57600);
delay(1000);
serial.print("ready!");
}
void loop() {
switch (check){
case 0:
{
//wait timestamp
waittoread("time");
serial.println("time set");
check = 1;
break;
}
case 1:
{
//collect data
delay(3000);
check = 2;
break;
}
case 2:
{
//send data hub
delay(1000);
serial.print("datahub!");
check = 0;
}
}
}
void waittoread(string wantstring){
string readstr = "";
//looking string terminated ! - "hello!" "bye!" "66r3!", etc.
while(!wantstring.equals(readstr)){
while (serial.available()) {
delay(10); //small delay allow input buffer fill
char c = serial.read(); //gets 1 byte serial buffer
if (c == '!') {
break;
} //breaks out of capture loop print readstring
readstr += c;
} //makes string readstring
}
}
and
hub:
code: [select]
#define xbee_id 0
int check = 0;
void setup() {
serial.begin(57600);
delay(100);
//first connection
waittoread("ready");
}
void loop() {
switch (check){
case 0:
{
delay(2000);
serial.print("time!");
check = 1;
}
case 1:
{
waittoread("datahub");
check = 0;
}
}
}
void waittoread(string wantstring){
string readstr = "";
//looking string terminated ! - "hello!" "bye!" "66r3!", etc.
while(!wantstring.equals(readstr)){
while (serial.available()) {
delay(10); //small delay allow input buffer fill
char c = serial.read(); //gets 1 byte serial buffer
if (c == '!') {
break;
} //breaks out of capture loop print readstring
readstr += c;
} //makes string readstring
}
}
now isn't - have entirety of "meat" of programs written in file, everything's running simultaneously, want put framework , more control on everything. aaaand i'm stuck. nothing seems work. i'm not coming clean enough way switch between 'reading' , 'sending', , xbees either getting nothing @ all, or compounding message last thing received , going sort of feedback loop.
any advice @ how control system better wonderful. unfortunately obvious 1 (change hardware!) isn't going happen. gotta work i've got. however, hardware (at least @ moment!) set correctly - xbees sending , receiving perfectly, if load simple programs. problem code.
also - since xbees using serial port, there nice way me print debugging code without getting in way? not being able test parts of code has been huge pain.
Arduino Forum > Using Arduino > Programming Questions > State control - using commands sent over XBee wireless?
arduino
Comments
Post a Comment