Skip to content

Commit

Permalink
added button read in wplug
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Nov 14, 2016
1 parent 6cd9e03 commit c7abdf1
Show file tree
Hide file tree
Showing 4 changed files with 1,929 additions and 11 deletions.
54 changes: 45 additions & 9 deletions arduino_code/onos_plug_node_WPlugavx/onos_plug_node_wplugavx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ int timeout_to_turn_off=0;//0=disabled 600; //10 hours todo add the poss


char main_obj_state=0;
char old_main_obj_state=5;
//int old_main_obj_state=5;


int relay1_set_pin=5;
int relay1_reset_pin=6;
int relay2_set_pin=7;
int relay2_reset_pin=8;

int obj_button_pin=4;



Expand All @@ -187,14 +187,34 @@ int freeRam ()



void changeObjStatus(char obj_number,int status_to_set){
Serial.print("changeObjStatus executed with status:");
Serial.println(status_to_set);

if (obj_number==0){

digitalWrite(relay1_set_pin,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(100);
digitalWrite(relay1_set_pin,0);
digitalWrite(relay1_reset_pin,0);
digitalWrite(relay2_set_pin,0);
digitalWrite(relay2_reset_pin,0);
main_obj_state=status_to_set;
}



}


void composeSyncMessage(){


//[S_001ul3.05ProminiS0001000_#]
// example: [S_001ul3.05WPlugAvx00010167123_#] #lux=167 contact0 is at 0 , 123 minutes on since boot
//[S_123ul5.24WPlugAvx000810000_#]
// example deprecated: [S_001ul3.05WPlugAvx00010167123_#] #lux=167 contact0 is at 0 , 123 minutes on since boot
if (main_obj_state==1){

if (time_continuos_on!=0){
Expand Down Expand Up @@ -292,7 +312,7 @@ void composeSyncMessage(){
strcat(syncMessage, node_fw);
strcat(syncMessage, serial_number);


if (main_obj_state==0){
strcat(syncMessage,"0");
}
Expand Down Expand Up @@ -473,7 +493,7 @@ void decodeOnosCmd(const char *received_message){
main_obj_state=received_message[8]-48;

received_message_value=received_message[9]-48;


if (received_message_value>1){
Serial.println(F("er0_status_#]"));
Expand All @@ -497,6 +517,10 @@ void decodeOnosCmd(const char *received_message){



changeObjStatus(main_obj_selected,received_message_value);

/*
digitalWrite(relay1_set_pin,main_obj_state);
digitalWrite(relay1_reset_pin,!main_obj_state);
digitalWrite(relay2_set_pin,main_obj_state);
Expand All @@ -511,7 +535,7 @@ void decodeOnosCmd(const char *received_message){
digitalWrite(relay2_set_pin,0);
digitalWrite(relay2_reset_pin,0);
/*
time_continuos_on=millis();
while (digitalRead(received_message_second_pin_used)!=received_message_value){
delay(1);
Expand Down Expand Up @@ -635,12 +659,14 @@ void setup() {
pinMode(relay1_reset_pin, OUTPUT);
pinMode(relay2_set_pin, OUTPUT);
pinMode(relay2_reset_pin, OUTPUT);
pinMode(obj_button_pin, INPUT);


//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");
Expand Down Expand Up @@ -685,7 +711,17 @@ void loop() {

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


if (digitalRead(obj_button_pin)==0) {
Serial.print("obj_button pressed");
changeObjStatus(main_obj_selected,!main_obj_state); // this will make a not of current state
sendSyncMessage();
while (digitalRead(obj_button_pin)==0){ //wait for button release
delay(1);
}

}


if (radio.receiveDone()){
//print message received to serial
Serial.print('[');Serial.print(radio.SENDERID);Serial.print("] ");
Expand Down
13 changes: 11 additions & 2 deletions scripts_folder/arduinoserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ def read_data(self): # thread function

if ( (buf.find("[S_")!=-1)&(buf.find("_#]")!=-1) ): #there is a full onos command packet


print "packet 232 in :"+buf
time.sleep(1)
if write_to_serial_packet_ready==1:
last_received_packet=buf
write_to_serial_packet_ready=0
Expand All @@ -315,7 +316,15 @@ def read_data(self): # thread function
cmd=buf[cmd_start:cmd_end+3]


if( (cmd[6]=="s")&(cmd[7]=="y") )or((cmd[6]=="u")&(cmd[7]=="l")) : # [S_001sy3.05ProminiS0001_#]
if( (cmd[6]=="s")&(cmd[7]=="y") )or((cmd[6]=="u")&(cmd[7]=="l")) :
# [S_001sy3.05ProminiS0001_#] or [S_123ul5.24WPlugAvx000810000_#]

if ((cmd[6]=="u")&(cmd[7]=="l")):
obj_number_to_update=0
obj_value=cmd[24]
#todo update the first node obj reading the name from hardwaremodel


print "serial rx cmd="+cmd
buf=""
try:
Expand Down
Binary file modified scripts_folder/arduinoserial.pyc
Binary file not shown.

0 comments on commit c7abdf1

Please sign in to comment.