Skip to content

Commit

Permalink
added digital pin read to serialnode ,removed all the strings objects…
Browse files Browse the repository at this point in the history
… in the arduino code of onos_node_Plug6way.pde and onos_rf69_serial_transponder.pde
  • Loading branch information
marco committed Aug 18, 2016
1 parent b0f3085 commit 9331db1
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 742 deletions.
579 changes: 275 additions & 304 deletions arduino_code/onos_node_Plug6way.pde

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion arduino_code/onos_node_ProminiA2.pde
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Wire up as following (ENC = module side):

//#define DEVMODE3 1

String setup_msg="";

EthernetClient client;
signed long next;
uint8_t digital_setup[10];
Expand Down
9 changes: 5 additions & 4 deletions scripts_folder/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def readDictionaryFromSavedFile(key):
json_file = codecs.open(base_cfg_path+"config_files/data.json",'r',"utf8")
readed_data = json_file.read()
json_file.close()
readed_dict=json.loads(readed_data)
except:
print "can't import data.json file , i will load the recovery one "
readed_data=recoverydata_json # is in globalVar.py
Expand Down Expand Up @@ -236,12 +237,12 @@ def importConfig():



tmp_node_dict=readDictionaryFromSavedFile("nodeDictionary")
tmp_node_dict=readDictionaryFromSavedFile(u"nodeDictionary")
for a in tmp_node_dict.keys(): #for each node in the file
node_serial_number=tmp_node_dict[a]["node_serial_number"]
node_type=tmp_node_dict[a]["hwModelName"]
node_serial_number=tmp_node_dict[a][u"node_serial_number"]
node_type=tmp_node_dict[a][u"hwModelName"]
#node_sn=tmp_node_dict[a]["node_serial_number"]
node_address=tmp_node_dict[a]["nodeAddress"]
node_address=tmp_node_dict[a][u"nodeAddress"]
hardware_node_type=hardwareModelDict[node_type]
nodeDict[node_serial_number]=hw_node.HwNode(node_serial_number,hardware_node_type,node_address,router_hardware_fw_version)
#ricreate the nodeDict from the json backup
Expand Down
4 changes: 2 additions & 2 deletions scripts_folder/config_files/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"objectDictionary": {
},
"roomDictionary": {
}
},
"scenarioDictionary": {
}

}

12 changes: 6 additions & 6 deletions scripts_folder/router_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,statu
address=node_obj.getNodeAddress()
base_query='' #' ''http://'''+address+''':'''+str(node_webserver_port) not used anymore
if (out_type=="sr_relay"):
pin1=str(pinNumbers[0])
pin0=str(pinNumbers[1])
pin1=str(pinNumbers[1])
pin0=str(pinNumbers[0])
if (len (pin0) <2):
pin0='0'+pin0
if (len (pin1) <2):
Expand Down Expand Up @@ -381,7 +381,7 @@ def composeChangeNodeOutputPinStatusQuery(self,pinNumbers,node_obj,objName,statu



def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,previous_status,statusToSet,output_type,user,priority,mail_report_list):
def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,previous_status,statusToSetWebObject,output_type,user,priority,mail_report_list):


print "executed router_handler digitalwrite()"
Expand Down Expand Up @@ -474,7 +474,7 @@ def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,prev



priorityCmdQueue.put( {"cmd":"setSts","webObjectName":objName,"status_to_set":statusToSet,"write_to_hw":0,"user":user,"priority":priority,"mail_report_list":mail_report_list })
priorityCmdQueue.put( {"cmd":"setSts","webObjectName":objName,"status_to_set":statusToSetWebObject,"write_to_hw":0,"user":user,"priority":priority,"mail_report_list":mail_report_list })
return(1)

else: #the router has't got IO pins
Expand All @@ -484,7 +484,7 @@ def outputWrite(self,node_serial_number,pinList,statusList,node_obj,objName,prev



if ((str(node_address))=="1"): #a local arduino selected not implemented yet
if ((str(node_address))=="0001"): #a local arduino selected not implemented yet
print "i write to/from a remote node selected"
#self.makeChangeWebObjectStatusQuery(objName,statusToSet) #banana to remove
if ((self.arduino_used==1)&(node_address=="1")): #check if arduino is enabled correctly and is selected with 1
Expand Down Expand Up @@ -527,7 +527,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,statusToSet,node_serial_number,output_type,user,priority,mail_report_list)
self.composeChangeNodeOutputPinStatusQuery(pinList,node_obj,objName,statusList[0],node_serial_number,output_type,user,priority,mail_report_list)
return(1)
else:
print "error number of pins !=2"
Expand Down
10 changes: 5 additions & 5 deletions scripts_folder/web_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class WebObject:

def __init__(self,name,obj_type="b",start_status=0,styleDictionary={},htmlDictionary={},cmdDictionary={},note=" ",hardware_pin=[9999],HwNodeSerialNumber=0,spareDict={}):
self.__object_type=obj_type
self.__style0="background-color:green ;"
self.__style1="background-color:red ;"
self.__style0="background-color:red ;"
self.__style1="background-color:green ;"
self.styleDict={u"0":self.__style0,u"1":self.__style1,u"onoswait":"background-color:grey ;color black","default_s":"background-color:red ;color black"}
self.styleDict.update(styleDictionary)
self.__style0=self.styleDict[u"0"]
self.__style1=self.styleDict[u"1"]
self.__style0=self.styleDict[u"1"]
self.__style1=self.styleDict[u"0"]
self.style_wait=self.styleDict[u"onoswait"] #banana to remove

self.htmlDict={u"0":name+"=0",u"1":name+"=1"}
self.htmlDict={u"0":name+"=0",u"1":name+"=1"}

self.htmlDict.update(htmlDictionary)

Expand Down
75 changes: 54 additions & 21 deletions scripts_folder/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,22 +1400,32 @@ def updateOneRoom(room):
file0.write(fileToWrite)
file0.close()
#os.system("chmod 777 "+html_file_location)
with lock_bash_cmd:
subprocess.call("chmod 777 "+html_file_location, shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.call("chmod 777 "+html_file_location, shell=True,close_fds=True)
os.chmod(html_file_location, 0o777)


else:
print "i make the directory"+room
#os.system("mkdir "+baseRoomPath+room)
with lock_bash_cmd:
subprocess.call("mkdir "+baseRoomPath+room, shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.call("mkdir "+baseRoomPath+room, shell=True,close_fds=True)


try:
os.stat(baseRoomPath+room)
except:
os.mkdir(baseRoomPath+room)

fileToWrite=getRoomHtml(room,object_dict,"",zoneDict)
file0 = open(baseRoomPath+room+"/index.html", "w")
file0.write(fileToWrite)

file0.close()
#os.system("chmod 777 "+html_file_location)
with lock_bash_cmd:
subprocess.call("chmod 777 "+html_file_location, shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.call("chmod 777 "+html_file_location, shell=True,close_fds=True)
os.chmod(html_file_location, 0o777)
return

def updateDir():
Expand All @@ -1433,20 +1443,28 @@ def updateDir():
file0.write(fileToWrite)
file0.close()
#os.system("chmod 777 "+baseRoomPath+zone+"/index.html")
with lock_bash_cmd:
subprocess.call("chmod 777 "+baseRoomPath+zone+"/index.html", shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.call("chmod 777 "+baseRoomPath+zone+"/index.html", shell=True,close_fds=True)
os.chmod(baseRoomPath+zone, 0o777)
else:
print "create the file"+index
#os.system("mkdir "+baseRoomPath+zone)
with lock_bash_cmd:
subprocess.call("mkdir "+baseRoomPath+zone, shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.call("mkdir "+baseRoomPath+zone, shell=True,close_fds=True)

try:
os.stat(baseRoomPath+zone)
except:
os.mkdir(baseRoomPath+zone)

fileToWrite=getRoomHtml(zone,object_dict,"",zoneDict)
try:
file0 = open(index, "w")
file0.write(fileToWrite)
file0.close()
with lock_bash_cmd:
subprocess.call("chmod 777 "+baseRoomPath+zone+"/index.html", shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.call("chmod 777 "+baseRoomPath+zone+"/index.html", shell=True,close_fds=True)
os.chmod(baseRoomPath+zone, 0o777)
except Exception, e:
print "error creating "+baseRoomPath+zone+"/index.html e:" +str(e.args)
errorQueue.put("error creating "+baseRoomPath+zone+"/index.html e:" +str(e.args))
Expand Down Expand Up @@ -1495,8 +1513,14 @@ def createNewNode(node_sn,node_ip,node_fw):

#create a new web_object and insert only his name
#os.system("mkdir "+baseRoomPath+node_sn)
with lock_bash_cmd:
subprocess.check_output("mkdir "+baseRoomPath+node_sn, shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.check_output("mkdir "+baseRoomPath+node_sn, shell=True,close_fds=True)


try:
os.stat(baseRoomPath+node_sn)
except:
os.mkdir(baseRoomPath+node_sn)

createNewWebObjFromNode(hwType,node_sn)
try:
Expand All @@ -1510,8 +1534,10 @@ def createNewNode(node_sn,node_ip,node_fw):

#os.system("cat "+getRoomHtml(node_sn,object_dict,"",zoneDict)+" >> "+baseRoomPath+node_sn+"/index.html")
#os.system("chmod 777 "+baseRoomPath+node_sn)
with lock_bash_cmd:
subprocess.check_output("chmod 777 "+baseRoomPath+node_sn, shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.check_output("chmod 777 "+baseRoomPath+node_sn, shell=True,close_fds=True)

os.chmod(baseRoomPath+node_sn, 0o777)
print "create a new zone"+node_sn
#print zoneDict
updateOneRoom(node_sn)
Expand Down Expand Up @@ -3776,8 +3802,10 @@ def do_POST(self): #get posts data

try :
#os.system("mv "+baseRoomPath+room+" "+baseRoomPath+new_name) #rename the directory
with lock_bash_cmd:
subprocess.check_output("mv "+baseRoomPath+room+" "+baseRoomPath+new_name, shell=True,close_fds=True)
#with lock_bash_cmd:
# subprocess.check_output("mv "+baseRoomPath+room+" "+baseRoomPath+new_name, shell=True,close_fds=True)
os.rename(baseRoomPath+room, baseRoomPath+new_name,)

updateOneRoom(new_name)

print ("mv "+room+" "+new_name)
Expand All @@ -3801,11 +3829,16 @@ def do_POST(self): #get posts data
#os.system("cat "+getRoomHtml(new_name,object_dict,"",zoneDict)+" >> "+baseRoomPath+new_name+"/index.html")
#os.system("chmod 777 "+new_name)

try:
os.stat(baseRoomPath+new_name)
except:
os.mkdir(baseRoomPath+new_name)

with lock_bash_cmd:
subprocess.check_output("mkdir "+baseRoomPath+new_name, shell=True,close_fds=True)
#subprocess.check_output("mkdir "+baseRoomPath+new_name, shell=True,close_fds=True)
subprocess.check_output("cat "+getRoomHtml(new_name,object_dict,"",zoneDict)+" >> "+baseRoomPath+new_name+"/index.html", shell=True,close_fds=True)
subprocess.check_output("chmod 777 "+new_name, shell=True,close_fds=True)

#subprocess.check_output("chmod 777 "+new_name, shell=True,close_fds=True)
os.chmod(new_name, 0o777)
updateOneRoom(new_name)
print "create a new room"+new_name
data_to_update=1
Expand Down

0 comments on commit 9331db1

Please sign in to comment.