Skip to content

Commit

Permalink
modified onos_plug_node_wplugavx.ino , now it has many functions call…
Browse files Browse the repository at this point in the history
…ed from the main loop
  • Loading branch information
marco committed Dec 29, 2016
1 parent c8ebac1 commit d5ed7f9
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 106 deletions.
221 changes: 119 additions & 102 deletions arduino_code/onos_plug_node_WPlugavx/onos_plug_node_wplugavx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ boolean changeObjStatus(char obj_number,int status_to_set){
digitalWrite(relay1_reset_pin,!status_to_set);
digitalWrite(relay2_set_pin,status_to_set);
digitalWrite(relay2_reset_pin,!status_to_set);
delay(210);
delay(20);
digitalWrite(relay1_set_pin,0);
digitalWrite(relay1_reset_pin,0);
digitalWrite(relay2_set_pin,0);
Expand Down Expand Up @@ -732,101 +732,9 @@ void decodeOnosCmd(const char *received_message){

}// end of decodeOnosCmd()

void handleButton(){

if (digitalRead(obj_button_pin)==0) {
Serial.print("obj_button pressed");

while (digitalRead(obj_button_pin)==0){ //wait for button release
delay(280);//todo change it smaller
}

changeObjStatus(main_obj_selected,!main_obj_state); // this will make a not of current state
sendSyncMessage(radioRetry+2,radioTxTimeout);


}


}



void setup() {

while (!Serial); // wait until serial console is open, remove if not tethered to computer
noInterrupts(); // Disable interrupts //important for lamp node

pinMode(RFM69_RST, OUTPUT);


pinMode(relay1_set_pin, OUTPUT);
pinMode(relay1_reset_pin, OUTPUT);
pinMode(relay2_set_pin, OUTPUT);
pinMode(relay2_reset_pin, OUTPUT);
pinMode(obj_button_pin, INPUT);
pinMode(obj_led_pin, OUTPUT);

//while (!Serial); // wait until serial console is open, remove if not tethered to computer
Serial.begin(SERIAL_BAUD);


digitalWrite(obj_button_pin, HIGH); //enable pull up resistors


Serial.println("Feather RFM69W Receiver");



// Hard Reset the RFM module

digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);


interrupts(); // Enable interrupts

// Initialize radio
radio.initialize(FREQUENCY,this_node_address,NETWORKID);
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)

radio.encrypt(ENCRYPTKEY);

pinMode(LED, OUTPUT);

radio.enableAutoPower(targetRSSI);

Serial.print("\nListening at ");
Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(" MHz");

composeSyncMessage();


}

void loop() {



//check if something was received (could be an interrupt from the radio)

handleButton();

if (skipRadioRxMsg>skipRadioRxMsgThreshold){ //to allow the execution of radio tx , in case there are too many rx query..
skipRadioRxMsg=0; //reset the counter to allow this node to receive query
Serial.println("I skip the rxradio part once");
goto radioTx;


}


void checkAndHandleIncomingRadioMsg(){

if (radio.receiveDone()){

Expand Down Expand Up @@ -893,6 +801,8 @@ void loop() {
}
else{
Serial.println("error in message decode i will not send the ACK");
// checkCurrentRadioAddress(); //if the mesage received is wrong i will check and send a address request if needed becausethe onos gateway will wait a moment after the tranmission failure.

//interrupts(); // Enable interrupts
}

Expand All @@ -911,18 +821,35 @@ void loop() {
}// end if (radio.receiveDone())


radioTx:

radio.receiveDone(); //put radio in RX mode
Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU
}







void handleButton(){

if (digitalRead(obj_button_pin)==0) {
Serial.print("obj_button pressed");

while (digitalRead(obj_button_pin)==0){ //wait for button release
delay(280);//todo change it smaller
}

changeObjStatus(main_obj_selected,!main_obj_state); // this will make a not of current state
sendSyncMessage(radioRetry+2,radioTxTimeout);


}


}



void checkCurrentRadioAddress(){


if (old_address==254){// i have not the proper address yet..
Expand Down Expand Up @@ -954,19 +881,109 @@ radioTx:


}
else{

else if ((millis()-sync_time)>2000){ //every 5000 ms

if ((millis()-sync_time)>2000){ //every 5000 ms

sync_time=millis();
sync_time=millis();

sendSyncMessage(radioRetry,radioTxTimeout);


}

}



}


void setup() {

while (!Serial); // wait until serial console is open, remove if not tethered to computer
noInterrupts(); // Disable interrupts //important for lamp node

pinMode(RFM69_RST, OUTPUT);


pinMode(relay1_set_pin, OUTPUT);
pinMode(relay1_reset_pin, OUTPUT);
pinMode(relay2_set_pin, OUTPUT);
pinMode(relay2_reset_pin, OUTPUT);
pinMode(obj_button_pin, INPUT);
pinMode(obj_led_pin, OUTPUT);

//while (!Serial); // wait until serial console is open, remove if not tethered to computer
Serial.begin(SERIAL_BAUD);


digitalWrite(obj_button_pin, HIGH); //enable pull up resistors


Serial.println("Feather RFM69W Receiver");


sendSyncMessage(radioRetry,radioTxTimeout);

// Hard Reset the RFM module

digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);


interrupts(); // Enable interrupts

// Initialize radio
radio.initialize(FREQUENCY,this_node_address,NETWORKID);
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)

radio.encrypt(ENCRYPTKEY);

pinMode(LED, OUTPUT);

radio.enableAutoPower(targetRSSI);

Serial.print("\nListening at ");
Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(" MHz");

composeSyncMessage();


}

void loop() {



//check if something was received (could be an interrupt from the radio)

handleButton();

if (skipRadioRxMsg>skipRadioRxMsgThreshold){ //to allow the execution of radio tx , in case there are too many rx query..
skipRadioRxMsg=0; //reset the counter to allow this node to receive query
Serial.println("I skip the rxradio part once");
goto radioTx;


}



checkAndHandleIncomingRadioMsg();


radioTx:

radio.receiveDone(); //put radio in RX mode
Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU

checkCurrentRadioAddress();


}//END OF LOOP()
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ versione4.53 iniziato ad usare pythonserial come libraria dopo test fatti con
to clear the arrays in the arduino programs,before i used strcpy(filtered_onos_message,"") that doesn't work well
reduced the radio.sendWithRetry timeout from 200ms t0 75ms and increased the retry from 1 to 3
modified a lot of parts...now the radio communication is faster and more stable (tried only one node)
modified onos_plug_node_wplugavx.ino , now it has many functions called from the main loop.



(110, 'Connection timed out');;;
Expand Down
8 changes: 4 additions & 4 deletions scripts_folder/config_files/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
],
"priority": 0,
"scenarios": [],
"status": 1,
"status": "onoswait",
"styleDict": {
"0": "background-color:#A9E2F3;",
"1": "background-color:#8181F7;",
Expand Down Expand Up @@ -666,7 +666,7 @@
],
"priority": 0,
"scenarios": [],
"status": 1331,
"status": 1349,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -756,7 +756,7 @@
"scenario4",
"scenario8"
],
"status": 11,
"status": 29,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -864,7 +864,7 @@
],
"priority": 0,
"scenarios": [],
"status": 1,
"status": "onoswait",
"styleDict": {
"0": "background-color:#A9E2F3;",
"1": "background-color:#8181F7;",
Expand Down

0 comments on commit d5ed7f9

Please sign in to comment.