Skip to content

Commit

Permalink
now onos will not crash if there is not a serial port connected, chan…
Browse files Browse the repository at this point in the history
…ged Serial_connection_Handler.py
  • Loading branch information
marco committed Jan 4, 2017
1 parent 1b57043 commit 07c81fc
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 183 deletions.
4 changes: 2 additions & 2 deletions arduino_code/onos_rf69_serial_transponder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_433MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HCW false // set to 'true' if you are using an RFM69HCW module
#define IS_RFM69HCW true // set to 'true' if you are using an RFM69HCW module

//*********************************************************************************************
#define SERIAL_BAUD 115200
Expand Down Expand Up @@ -834,7 +834,7 @@ void forwardRadioMsgToSerialPort(){

void setup() {

// delay(95000); //wait for glinet to power on
delay(95000); //wait for glinet to power on
while (!Serial); // wait until serial console is open
Serial.begin(SERIAL_BAUD);

Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ versione4.53 iniziato ad usare pythonserial come libraria dopo test fatti con
modified onos_plug_node_wplugavx.ino , now it has many functions called from the main loop.
modified webserver.py now the nodes will not be able to change a object status
if the current status is onoswait if object_dict[objName].getStatus()=="onoswait
now onos will not crash if there is not a serial port connected, changed Serial_connection_Handler.py



(110, 'Connection timed out');;;
Expand Down
4 changes: 2 additions & 2 deletions online_db/new_onos_center_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<body>

<form action="create_new_onos_center.php" method="post">
onos_key: <input type="text" name="onos_key"><br>
onos_Password:<input type="password" size="18" name="pass" />
onos_online_key: <input type="text" name="onos_key"><br>
onos_online_password:<input type="password" size="18" name="pass" />
<br>
<input type="submit">
</form>
Expand Down
10 changes: 7 additions & 3 deletions online_db/procedure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
How to use the onos online database:


1)First create the new onoscenter user , key and password using the form :
1)First create the new onoscenter , onos_online_key and onos_online_password using the form :
"new_onos_center_form.html" , it will call create_new_onos_center.php wich will create a new db in the folder "users_db"


Expand All @@ -16,13 +16,17 @@ How to use the onos online database:
"login_error_page.php" will be executed wich will ask you to reinsert the data.


4)To insert some example data in the database you could run python_post_send.py from your local pc .
4)Create a local username with the same data used to compile new_onos_user_form.html



5)To insert some example data in the database you could run python_post_send.py from your local pc .





3)To fake a onos connection and make an example of data transmission you can use "fake_form_db_sync.php"
6)To fake a onos connection and make an example of data transmission you can use "fake_form_db_sync.php"



Expand Down
122 changes: 33 additions & 89 deletions scripts_folder/Serial_connection_Handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,38 @@
ser=0
baud_rate=115200
class Serial_connection_Handler():
exluded_port_list=[]

def __init__(self):
self.exit=0
self.uart=self.connectToPort()
self.working=1
self.exluded_port_list
i=0
while (self.uart ==0) : #while port is not connected retry to connect banana to make it clever..
print ("retry serial connection number:"+str(i))
self.uart=self.connectToPort()
if self.uart==1:
break
time.sleep(1)
if i>2: #after 60 tries i increase the time between the tries
time.sleep(30)
if i>4: #after 120 tries i increase the time between the tries
time.sleep(60)

if i >10:
if (searchForSerialCable=="null"):
print "error serial connection, no serial ports found"
if i>2: #after n tries i increase the time between the tries
time.sleep(10)
if i>4: #after n tries i increase the time between the tries
time.sleep(30)

if i >0:
if (self.searchForSerialCable(self.exluded_port_list )=="null"):
print ("error serial connection, no serial ports found")
self.uart==-1
self.working=0
return(-1)


i=i+1


def reconnectSerialPort():

print("reconnectSerialPort() executed")
self.exluded_port_list=[]
self.uart=self.connectToPort()
self.working=1
i=0
Expand All @@ -57,44 +62,31 @@ def reconnectSerialPort():
time.sleep(60)

if i >10:
if (searchForSerialCable=="null"):
if (self.searchForSerialCable(self.exluded_port_list )=="null"):
print "error serial reconnection, no serial ports found"
self.working=0
return(-1)




def verifyPort(self,port_to_search,port_exluded):
if port_to_search!=port_exluded:
result=os.path.exists("/dev/"+port_to_search)
else:
return("no")

#result=os.popen("ls /dev/ | grep -v "+port_exluded+" | grep "+port_to_search).read()
if result:
return (port_to_search)
else:
return ("no")



def connectToPort(self):

port=self.searchForSerialCable("nothing")
print("connectSerialPort() executed")
port=self.searchForSerialCable(self.exluded_port_list )
if port!="null": # if i found the port then use it
try:
old_port=port # [0:len(port)-1]
#old_port=port # [0:len(port)-1]
port='/dev/'+port # [0:len(port)-1] #remove /n of ls
self.ser =arduinoserial.SerialPort(port, baud_rate)
print "arduino connected correctly to onos system"
return(self.ser)
except: #some error occured while using the port i found
print "port error i will retry with another port"
port=self.searchForSerialCable(old_port)
print "port error with port:"+port+" i will retry with another port"
if port not in self.exluded_port_list:
self.exluded_port_list.append(port)
port=self.searchForSerialCable(self.exluded_port_list )
if port!="null": # if i found the port then use it
try:
old_port=port[0:len(port)-1]
#old_port=port[0:len(port)-1]
port='/dev/'+port #[0:len(port)-1] #remove /n of ls
self.ser =arduinoserial.SerialPort(port, baud_rate)
print "arduino connected correctly to onos system"
Expand All @@ -112,81 +104,33 @@ def connectToPort(self):



def searchForSerialCable(self,exluded_port):

def searchForSerialCable(self,list_of_port_to_not_use):
print ("searchForSerialCable() executed with self.exluded_port_list= "+str(list_of_port_to_not_use))
list_of_dev=os.listdir("/dev")

for dev in list_of_dev:
if (dev.find("ttyATH0")!=-1)and(dev!=exluded_port):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyUSB0")!=-1)and(dev!=exluded_port):
if (dev.find("ttyATH")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyUSB1")!=-1)and(dev!=exluded_port):
if (dev.find("ttyUSB")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyUSB2")!=-1)and(dev!=exluded_port):
if (dev.find("ttyACM")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyUSB3")!=-1)and(dev!=exluded_port):
if (dev.find("ttyS")!=-1)and('/dev/'+dev not in list_of_port_to_not_use):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyACM0")!=-1)and(dev!=exluded_port):
return(dev)
return("null")

for dev in list_of_dev:
if (dev.find("ttyACM1")!=-1)and(dev!=exluded_port):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyACM2")!=-1)and(dev!=exluded_port):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyACM3")!=-1)and(dev!=exluded_port):
return(dev)

for dev in list_of_dev:
if (dev.find("ttyS0")!=-1)and(dev!=exluded_port):
return(dev)


port=self.verifyPort("ttyUSB0",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyUSB1",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyUSB2",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyUSB3",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyUSB4",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyUSB",exluded_port)

if len (port)<3:
port=self.verifyPort("ttyACM0",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyACM1",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyACM2",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyACM3",exluded_port)
if len (port)<3:
port=self.verifyPort("ttyACM",exluded_port)
if len (port)<3:
return("null")

return(port)




def __del__(self):
print ("class Serial_connection_Handler destroyed")



Expand Down
Binary file modified scripts_folder/Serial_connection_Handler.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions scripts_folder/arduinoserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(self, serialport, bps):


self.ser.open()




Expand Down Expand Up @@ -185,7 +185,7 @@ def read_data(self): # thread function
except:
print "I tried to reconnect serial port from arduinoserial module but I failed"
errorQueue.put("I tried to reconnect serial port from arduinoserial module but I failed")
priorityCmdQueue.put( {"cmd":"reconnectSerialPort"})
#priorityCmdQueue.put( {"cmd":"reconnectSerialPort"})
self.exit=1


Expand Down
Binary file modified scripts_folder/arduinoserial.pyc
Binary file not shown.
14 changes: 11 additions & 3 deletions scripts_folder/config_files/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"logTimeout": 15,
"login_required": 0,
"mail_whiteList": [],
"online_server_enable": 0,
"online_server_enable": 1,
"online_usersDict": {
"RouterGA0000": {
"mail_control_password": "1234",
Expand All @@ -20,7 +20,15 @@
"pw": "1234",
"user_mail": "elettronicaopensource@gmail.com"
}

"mauro": {
"mail_control_password": "onosm",
"priority": 0,
"pw": "12345678",
"user_mail": "elettronicaopensource@gmail.com"
}

},
"scenarios_enable": 0,
"scenarios_enable": 1,
"timezone": "CET-1CEST,M3.5.0,M10.5.0/3"
}
}
20 changes: 10 additions & 10 deletions scripts_folder/config_files/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
],
"priority": 0,
"scenarios": [],
"status": "onoswait",
"status": "inactive",
"styleDict": {
"0": "background-color:#A9E2F3;",
"1": "background-color:#8181F7;",
Expand Down Expand Up @@ -453,7 +453,7 @@
],
"priority": 0,
"scenarios": [],
"status": "onoswait",
"status": "inactive",
"styleDict": {
"0": "background-color:#A9E2F3;",
"1": "background-color:#8181F7;",
Expand Down Expand Up @@ -630,7 +630,7 @@
],
"priority": 0,
"scenarios": [],
"status": 29,
"status": 3,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -666,7 +666,7 @@
],
"priority": 0,
"scenarios": [],
"status": 1387,
"status": 997,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -710,7 +710,7 @@
"scenario5",
"scenario4"
],
"status": 23,
"status": 16,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -756,7 +756,7 @@
"scenario4",
"scenario8"
],
"status": 7,
"status": 37,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -792,7 +792,7 @@
],
"priority": 0,
"scenarios": [],
"status": 12,
"status": 1,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down Expand Up @@ -864,7 +864,7 @@
],
"priority": 0,
"scenarios": [],
"status": "onoswait",
"status": "0",
"styleDict": {
"0": "background-color:#A9E2F3;",
"1": "background-color:#8181F7;",
Expand Down Expand Up @@ -899,7 +899,7 @@
],
"priority": 0,
"scenarios": [],
"status": "onoswait",
"status": "inactive",
"styleDict": {
"0": "background-color:#A9E2F3;",
"1": "background-color:#8181F7;",
Expand Down Expand Up @@ -1635,7 +1635,7 @@
"scenarios": [
"scenarioA"
],
"status": 2016,
"status": 2017,
"styleDict": {
"0": "background-color:green;",
"1": "background-color:red;",
Expand Down

0 comments on commit 07c81fc

Please sign in to comment.