Skip to content

Commit

Permalink
updated the plug6way node to handle the new protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Aug 21, 2016
1 parent c0c15c3 commit aa83284
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 25 deletions.
23 changes: 18 additions & 5 deletions arduino_code/onos_node_Plug6way.pde
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ EthernetServer server = EthernetServer(9000); //port number 9000



#define serial_msg_lenght 21
#define serial_msg_lenght 23


char serial_message_type_of_onos_cmd;
char serial_message_flag;
uint8_t serial_message_address;
uint8_t serial_message_first_pin_used;
uint8_t serial_message_second_pin_used;
int serial_message_value;
char serial_message_answer[24]="er00_#]";
char serial_message_sn[5]="";
uint8_t serial_node_address=0;


uint8_t counter;
boolean enable_print=0;
Expand Down Expand Up @@ -128,6 +132,18 @@ void decodeOnosCmd(char received_message[]){
serial_message_sn[2]=received_message[15];
serial_message_sn[3]=received_message[16];

serial_message_flag=received_message[17];

serial_node_address=(received_message[18]-48)*100+(received_message[19]-48)*10+(received_message[20]-48)*1;

/*
Serial.println(serial_message_sn);
Serial.println(serial_message_flag);
Serial.println(serial_node_address);
*/




serial_message_type_of_onos_cmd=received_message[5];
Expand Down Expand Up @@ -415,10 +431,7 @@ void server_handler(EthernetClient client_query ){
decodeOnosCmd(filtered_onos_message);

if(((serial_message_answer[0]=='o')&&(serial_message_answer[1]=='k'))||(strcmp(serial_message_answer,"remote_#]")==0)){
char onos_cmd_type= serial_message_type_of_onos_cmd;
uint8_t onos_first_pin_used=serial_message_first_pin_used;
uint8_t onos_second_pin_used=serial_message_second_pin_used;
uint8_t onos_status_to_set=serial_message_value;



/*
Expand Down
4 changes: 3 additions & 1 deletion arduino_code/onos_rf69_serial_transponder.pde
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ void decodeOnosCmd(const char *received_message){

serial_node_address=(received_message[18]-48)*100+(received_message[19]-48)*10+(received_message[20]-48)*1;

/*
Serial.println(serial_message_sn);
Serial.println(serial_message_flag);
Serial.println(serial_node_address);

*/



Expand Down
29 changes: 18 additions & 11 deletions scripts_folder/router_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,31 +250,38 @@ def read_router_pins(self): # thread function to read changing of pin status



def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,status_to_set,node_serial_number,out_type,user,priority,mail_report_list) :
def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,status_to_set,node_serial_number,node_address,out_type,user,priority,mail_report_list) :

"""
| Compose the correct query to change an output pin status on a remote node.
| The examples are:
|
| "onos_r"+pin0+pin1+"v"+status_to_set+"s"+numeric_serial_number+"_#]" to set a sr_relay to status_to_set (0 or 1)
| onos_r0607v1s0001_#] pin6 and 7 used to control a s/r relay and turn it to set
| onos_r0607v1s0001f000_#] pin6 and 7 used to control a s/r relay and turn it to set
|
| "onos_d"+pin_number+"v"+"00"+status_to_set+"s"+numeric_serial_number+"_#]" to set a digital pin to 0 or 1
| onos_d07v001s0001_#] set digital pin7 to 1
| onos_d07v001s0001f000_#] set digital pin7 to 1
|
| "onos_s"+pin_number+"v"+status_to_set+"s"+numeric_serial_number+"_#]" to set a servopin from 0 to 180
| onos_s07v180s0001_#] set servo pin7 to 180
| onos_s07v180s0001f000_#] set servo pin7 to 180
|
| "onos_a"+pin_number+"v"+status_to_set+"s"+numeric_serial_number+"_#]" to set a analogpin from 0 to 255
| onos_a05v100s0001_#] set analog pin5 to 100
| onos_a05v100s0001f000_#] set analog pin5 to 100
|
| The numeric_serial_number is a hexadecimal number refering to the node serial number
| The node_address is a 3 byte ashii that rappresend the wireless node address(if the node is wireless,otherwise is ignored)
| the value must be between 0 and 255 it will be setted to "999" if is not used..
"""

print "composeChangeNodeOutputPinStatusQuery() executed"

if (len(node_address) >3): #to ignore powerline addresses..
node_address="999"

numeric_serial_number=node_serial_number[-4:] # example get 0001 from "ProminiA0001"
address=node_obj.getNodeAddress()
Expand All @@ -288,7 +295,7 @@ def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,statu
pin1='0'+pin1


query=base_query+'''onos_r'''+pin0+pin1+'''v'''+str(status_to_set)+'''s'''+numeric_serial_number+'''_#]'''
query=base_query+'''onos_r'''+pin0+pin1+'''v'''+str(status_to_set)+'''s'''+numeric_serial_number+"f"+node_address+'''_#]'''

if (out_type=="digital_output"):

Expand All @@ -299,7 +306,7 @@ def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,statu
pin='0'+pin

#onos_d07v001s0001_#]
query=base_query+'''onos_d'''+pin+'''v'''+'''00'''+str(status_to_set)+'''s'''+numeric_serial_number+'''_#]'''
query=base_query+'''onos_d'''+pin+'''v'''+'''00'''+str(status_to_set)+'''s'''+numeric_serial_number+"f"+node_address+'''_#]'''

if (out_type=="servo_output"):

Expand All @@ -313,7 +320,7 @@ def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,statu
status_to_set='0'+status_to_set

#onos_s07v180s0001_#]
query=base_query+'''onos_s'''+pin+'''v'''+status_to_set+'''s'''+numeric_serial_number+'''_#]'''
query=base_query+'''onos_s'''+pin+'''v'''+status_to_set+'''s'''+numeric_serial_number+"f"+node_address+'''_#]'''


if (out_type=="analog_output"):
Expand All @@ -328,7 +335,7 @@ def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,statu
status_to_set='0'+status_to_set

#onos_a07v100s0001_#]
query=base_query+'''onos_a'''+pin+'''v'''+status_to_set+'''s'''+numeric_serial_number+'''_#]'''
query=base_query+'''onos_a'''+pin+'''v'''+status_to_set+'''s'''+numeric_serial_number+"f"+node_address+'''_#]'''



Expand Down Expand Up @@ -527,7 +534,7 @@ def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,prev

if (output_type=="sr_relay"):
if (len(pinList)==2):
self.composeChangeNodeOutputPinStatusQuery(pinList,node_obj,objName,statusList[0],node_serial_number,output_type,user,priority,mail_report_list)
self.composeChangeNodeOutputPinStatusQuery(pinList,node_obj,objName,statusList[0],node_serial_number,node_address,output_type,user,priority,mail_report_list)
return(1)
else:
print "error number of pins !=2"
Expand All @@ -547,7 +554,7 @@ def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,prev
return(-1)


self.composeChangeNodeOutputPinStatusQuery(pinNumber,node_obj,objName,tmp_status_to_set,node_serial_number,output_type,user,priority,mail_report_list)
self.composeChangeNodeOutputPinStatusQuery(pinNumber,node_obj,objName,tmp_status_to_set,node_serial_number,node_address,output_type,user,priority,mail_report_list)
i=i+1
#start a thread query to the node

Expand Down
30 changes: 22 additions & 8 deletions tests/problems_and_solutions
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ I will use post instead that get message
1 byte to separe the pin number from the value , it will be 'v'
1 byte to tell arduino the status (0 or 1 ) to set the pin
1 byte to tell the node serial number
example : onos_d04v001s0001_#] to set pin 4 to 1 onos_d04v001s0001_#]
onos_d04v000s0001_#] to set pin 4 to 0 onos_d04v000s0001_#]
1 byte for a flag ,if flag=='f' then forward incoming message
3 byte for node address (used only for the wireless nodes but included also in the ethernet nodes..)
3 byte to close the message "_#]"


example : onos_d04v001s0001f001_#] to set pin 4 to 1 onos_d04v001s0001f001_#]
onos_d04v000s0001f001_#] to set pin 4 to 0 onos_d04v000s0001f001_#]


for analog pin it will be
Expand All @@ -166,8 +171,11 @@ I will use post instead that get message
1 byte to separe the pin number from the value , it will be 'v'
3 byte to tell arduino the value (0 or 255 ) to set the pin (to set 10 it will send '010',to set 255 it will send '255')
1 byte to tell the node serial number
example : onos_a11v255s0001_#] to set pin 11 to 255
onos_a11v099s0001_#] to set pin 11 to 99
1 byte for a flag ,if flag=='f' then forward incoming message
3 byte for node address (used only for the wireless nodes but included also in the ethernet nodes..)
3 byte to close the message "_#]"
example : onos_a11v255s0001f001_#] to set pin 11 to 255
onos_a11v099s0001f001_#] to set pin 11 to 99



Expand All @@ -178,8 +186,11 @@ I will use post instead that get message
1 byte to separe the pin number from the value , it will be 'v'
3 byte to tell arduino the value (0 or 180 ) to set the pin (to set 10 it will send '010',to set 180 it will send '180')
1 byte to tell the node serial number
example : onos_s05v180s0001_#] to set pin 5 to 180
onos_s05v090s0001_#] to set pin 5 to 90
1 byte for a flag ,if flag=='f' then forward incoming message
3 byte for node address (used only for the wireless nodes but included also in the ethernet nodes..)
3 byte to close the message "_#]"
example : onos_s05v180s0001f001_#] to set pin 5 to 180
onos_s05v090s0001f001_#] to set pin 5 to 90


for set/reset latch relay control it will be:
Expand All @@ -189,8 +200,11 @@ I will use post instead that get message
1 byte to separe the pin number from the value , it will be 'v'
1 byte to tell arduino the value (0 or 1 ) to set the relay
1 byte to tell the node serial number
example : onos_r0405v1s0001_#] to set the relay (set on pin 4 , reset on pin 5) to 1
onos_r0405v0s0001_#] to set the relay (set on pin 4 , reset on pin 5) to 0
1 byte for a flag ,if flag=='f' then forward incoming message
3 byte for node address (used only for the wireless nodes but included also in the ethernet nodes..)
3 byte to close the message "_#]"
example : onos_r0405v1s0001f001_#] to set the relay (set on pin 4 , reset on pin 5) to 1
onos_r0405v0s0001f001_#] to set the relay (set on pin 4 , reset on pin 5) to 0



Expand Down

0 comments on commit aa83284

Please sign in to comment.