Parcourir la source

上傳檔案到 'RS_GATEWAY'

allen il y a 4 ans
Parent
commit
4e43797c4c
3 fichiers modifiés avec 1164 ajouts et 0 suppressions
  1. 396 0
      RS_GATEWAY/RS_G_All_Ver2.py
  2. 348 0
      RS_GATEWAY/RS_G_All_Ver3.py
  3. 420 0
      RS_GATEWAY/RS_G_control.py

+ 396 - 0
RS_GATEWAY/RS_G_All_Ver2.py

@@ -0,0 +1,396 @@
+#!/usr/bin/env python
+#-*- coding: utf-8 -*-
+#-*- coding: cp950 -*-
+
+import array,time,threading,mraa,serial,urllib2,urllib,os,os.path,requests,traceback   #How to install?? ----> pip install requests
+from BBIOServer import *
+pin_net = mraa.Pwm(19)#use J8 to be power light
+pin_net.enable(True)
+pin_net.write(1)
+
+
+if True :
+	Old_Led_Data =""
+	New_Led_Data =""
+	Old_MP3_Data =""
+	New_MP3_Data =""
+	Old_Switch_Data =""
+	New_Switch_Data =""
+	Old_Switch_Data =""
+	New_Switch_Data =""
+	Old_Fans_Data =""
+	New_Fans_Data =""
+
+	list_Old = 0
+	play_Old = 0
+	vol_Old = 0
+	rep_Old = 0
+
+	array_rx = 100
+	rx=[0x00]*array_rx
+	ser=serial.Serial('/dev/ttyS0',38400,timeout=1)
+	validation = 0
+
+	number = 1
+	s_humidity = 0
+	s_t_near_stem = 0
+	s_water_frequency = 0
+	s_c2h4 = 0
+	s_temp = 0
+	s_wind_flow = 0
+	s_o3 = 0
+	s_n2 = 0
+	s_mf = 0
+	s_o2 = 0
+	s_co2 = 0
+	s_vibration = 0
+	s_h2 = 0
+	s_uv = 0
+	r_humidity = 0
+	r_air_temp = 0
+	r_water_temp_1 = 0
+	r_water_temp_2 = 0
+	r_water_temp_3 = 0
+	r_orp = 0
+	r_nh4 = 0
+	r_ph = 0
+	r_co2 = 0
+	r_mf = 0
+	r_sonic = 0
+	r_turbidity = 0
+	r_no3 = 0
+	r_ec = 0
+	r_ed = 0
+	r_do = 0
+	r_magnetic_level = 0
+	r_no2 = 0
+	r_wind_flow = 0
+	r_fluorine = 0
+	r_electric_current = 0
+	r_root_t = 0
+	r_chlorine = 0
+	r_soil_temp = 0
+	r_soil_moisture = 0
+	water_level = 0
+	#path = "http://13.113.114.87/b/tofitolab.php"
+	path ="http://13.113.114.87/20200312/tofitolab.php"
+
+
+def Led_RGB_OPCL(x):
+	global Old_Led_Data
+	global New_Led_Data
+	LED_path = "http://13.113.114.87/b/rgb.php"
+	mydata=[('led_sw',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_SW =urllib2.urlopen(req).read()
+	Led_SW = int(Led_SW)
+	#====================================
+	mydata=[('led_r',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_R =urllib2.urlopen(req).read()
+	Led_R = int(Led_R)
+	#====================================
+	mydata=[('led_g',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_G =urllib2.urlopen(req).read()
+	Led_G = int(Led_G)
+	#====================================
+	mydata=[('led_b',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_B =urllib2.urlopen(req).read()
+	Led_B = int(Led_B)
+	#====================================
+	mydata=[('led_ir',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_IR =urllib2.urlopen(req).read()
+	Led_IR = int(Led_IR)
+	#====================================
+	mydata=[('led_uv',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_UV =urllib2.urlopen(req).read()
+	Led_UV = int(Led_UV)
+	#====================================
+	New_Led_Data = str(Led_R) +str(Led_G) +str(Led_B) +str(Led_SW) +str(Led_IR) +str(Led_UV)
+	if (Old_Led_Data != New_Led_Data):
+		print"detected differently  transmitting signals"
+		print Old_Led_Data
+		print New_Led_Data
+		if Led_SW == 0:
+			commandarray=[0xFF,0xFF,0xF1,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Led_Data = New_Led_Data
+		if Led_SW == 1:
+			commandarray=[0xFF,0xFF,0xF1,0x01,Led_R,Led_G,Led_B,Led_IR,Led_UV,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Led_Data = New_Led_Data
+		time.sleep(0.3)
+		print "R =" + str(Led_R) + " G ="+ str(Led_G)+" B ="+ str(Led_B) + " IR ="+str(Led_IR)+ " UV ="+str(Led_UV)+ " SW ="+str(Led_SW)
+
+def MP3_OPCL(x):
+	global Old_MP3_Data
+	global New_MP3_Data
+	global list_Old
+	global vol_Old
+	global play_Old
+	global rep_Old
+	MP3_Path = "http://13.113.114.87/b/music.php"
+	##----------------------------------
+	mydata=[('list',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	list =urllib2.urlopen(req).read()
+	list = int(list)
+	##----------------------------------
+	mydata=[('play',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	play =urllib2.urlopen(req).read()
+	play = int(play)
+	##----------------------------------
+	mydata=[('vol',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	vol =urllib2.urlopen(req).read()
+	vol = int(vol)
+	##----------------------------------
+	mydata=[('rep',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	rep =urllib2.urlopen(req).read()
+	rep = int(rep)
+	##----------------------------------
+	New_MP3_Data = str(list) +str(play) +str(vol) +str(rep)
+	if (Old_MP3_Data != New_MP3_Data):
+		print"detected differently transmitting signals"
+		print Old_MP3_Data
+		print New_MP3_Data
+		if (play_Old != play):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x01,play,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			play_Old = play
+			print"send play pause signal"
+		if (vol_Old != vol ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x02,vol,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			vol_Old = vol
+			print"send volume signal"
+		if (rep_Old != rep ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x03,rep,list,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			rep_Old = rep
+			print"send a loop signal"
+		if (list_Old != list ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x04,list,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			list_Old = list
+			print"send repertory signal"
+		print commandarray
+		Old_MP3_Data = New_MP3_Data
+		print "repertory =" + str(list) + " playback ="+ str(play)+"volume ="+ str(vol) + " redundant ="+str(rep)
+		time.sleep(0.3)
+		print"launched"
+
+
+def webcam_photo():
+	try:
+		print time.strftime('%m.%d.%Y-%H:%M:%S ')
+		camera_box_l = "http://13.113.114.87/b/cam/camera1_1.php"
+		#os.system('fswebcam -r 320x240 -d v4l2:/dev/video0 --save /tmp/camera_1.jpg')
+		os.system('wget http://192.168.1.173:8080/?action=snapshot -O /tmp/camera_1.jpg')
+		time.sleep(1)
+		files = {'file': open('/tmp/camera_1.jpg', 'rb')}
+		time.sleep(1)
+		r = requests.post(camera_box_l, files=files)
+		time.sleep(2)
+	except Exception, e:
+		print 'traceback.print_exc():'; traceback.print_exc()
+		print ("There is a problem  please confirm")
+
+def Led_Data_Blink():
+	for i in range(0,3):
+		pin_net.write(0)
+		time.sleep(0.1)
+		pin_net.write(1)
+		time.sleep(0.1)
+
+def Switch_Control_OPCL(x):
+	global Old_Switch_Data
+	global New_Switch_Data
+	Switch_path = "http://13.113.114.87/b/liquidtanks_switch.php"
+	mydata=[('fid',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(Switch_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Switch_Control =urllib2.urlopen(req).read()
+	New_Switch_Data = Switch_Control
+
+
+	if (Old_Switch_Data != New_Switch_Data):
+		print"detected differently  transmitting signals"
+		Switch_Control = Switch_Control.split("j")
+		#print "Switch Count = " + str(len(Switch_Control))
+		#print Switch_Control[0:]
+		if True :
+			commandarray=[0xFF,0xFF,0xF1,0x03,int(Switch_Control[0]),int(Switch_Control[1]),int(Switch_Control[2]),int(Switch_Control[3]),int(Switch_Control[4]),int(Switch_Control[5]),int(Switch_Control[6]),int(Switch_Control[7]),int(Switch_Control[8]),int(Switch_Control[9]),int(Switch_Control[10]),int(Switch_Control[11]),0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Switch_Data = New_Switch_Data
+		print time.strftime(' %m/%d/%Y'+' %H:%M:%S'+' add ok')
+		time.sleep(0.3)
+		print "Switch =" + str(New_Switch_Data)
+
+
+def Fans_Control_OPCL(x):
+	global Old_Fans_Data
+	global New_Fans_Data
+	Fans_path = "http://13.113.114.87/b/wind_flow.php"
+	mydata=[('wind',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(Fans_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Fans_Control =urllib2.urlopen(req).read()
+	Fans_Control = int(Fans_Control)
+	New_Fans_Data = Fans_Control
+	if (Old_Fans_Data != New_Fans_Data):
+		print"detected differently  transmitting signals"
+
+		if True :
+			print "OK"
+			commandarray=[0xFF,0xFF,0xF1,0x04,Fans_Control,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			print commandarray
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Fans_Data = New_Fans_Data
+		print time.strftime(' %m/%d/%Y'+' %H:%M:%S'+' add ok')
+		print "Fans value=" + str(Old_Fans_Data)
+
+def Catch_Data():
+	global validation
+	if ser.inWaiting():
+		rx[0]=ser.read()
+		if rx[0] == '\xf1':
+			Switch_Control_OPCL(1)
+			print "Switch_Control_OPCL"
+		elif rx[0] == '\xf2':
+			Led_RGB_OPCL(1.1)
+			print "Led_RGB_OPCL"
+		elif rx[0] == '\xf3':
+			MP3_OPCL(1.1)
+			print "MP3_OPCL"
+		elif rx[0] == '\xf4':
+			Fans_Control_OPCL("1.1.1")
+			print "Fans_Control_OPCL"
+		elif rx[0]=='\xff':
+			validation +=1
+			rx[1]=ser.read()
+			if rx[1]=='\xff':
+				print "go updatta command old"
+				validation +=1
+				rx[2:array_rx]=ser.read(array_rx-2)############################
+				if rx[18]=='\x0d':############################
+					print "Rx[18] == 0D"
+					validation +=1
+				elif rx[array_rx-1]=='\x0d':############################
+					print "Rx[final] == 0D"
+					validation +=1
+				else:
+					validation=0 
+			else:
+				validation=0
+		else:
+			validation = 0
+	if validation ==3:
+		number= ord(rx[2])
+		case_command= ord(rx[3])
+		try:
+			if case_command ==02:
+				print "Go Case 02"
+				mydata = []
+				mydata.append(("number",number))
+				mydata.append(("type","norealtime"))
+				##############DHT22##############
+				s_temp = ord(rx[4])*256+ord(rx[5])
+				mydata.append(("s_temp",s_temp))
+				s_humidity = ord(rx[6])*256+ord(rx[7])
+				mydata.append(("s_humidity",s_humidity))
+				##############SHT22##############
+				r_air_temp = ord(rx[8])*256+ord(rx[9])
+				mydata.append(("r_air_temp",r_air_temp))
+				r_humidity = ord(rx[10])*256+ord(rx[11])
+				mydata.append(("r_humidity",r_humidity))
+				##############Cozir##############
+				s_co2= ord(rx[12])*256+ord(rx[13])
+				mydata.append(("s_co2",s_co2))
+				##############WaterTemp##############
+				r_water_temp_1 = ord(rx[14])*256+ord(rx[15]) 
+				mydata.append(("r_water_temp",r_water_temp_1))
+				r_water_temp_2 = ord(rx[16])*256+ord(rx[17])
+				mydata.append(("r_water_temp_2",r_water_temp_2))
+				r_water_temp_3 = ord(rx[18])*256+ord(rx[19])
+				mydata.append(("r_water_temp_3",r_water_temp_3))
+				##############PH##############
+				r_ph = ord(rx[20])*256+ord(rx[21])
+				mydata.append(("r_ph",r_ph))
+				##############soil Humid##############
+				r_soil_moisture = ord(rx[22])*256+ord(rx[23])
+				mydata.append(("r_soil_moisture",r_soil_moisture))
+				##############Turbidity##############
+				r_turbidity = ord(rx[24])*256+ord(rx[25])
+				mydata.append(("r_turbidity",r_turbidity))
+				##############Uv##############
+				s_uv = ord(rx[26])*256+ord(rx[27])
+				mydata.append(("s_uv",s_uv))
+				##############sonic##############
+				r_sonic = ord(rx[28])*256+ord(rx[29])
+				mydata.append(("r_sonic",r_sonic))
+				##############ORP##############
+				Df_Orp = ord(rx[30])*256+ord(rx[31])
+				mydata.append(("s_orp",Df_Orp))
+				##############RS485##############
+				r_orp = ord(rx[32])*256+ord(rx[33])
+				r_do = ord(rx[34])*256+ord(rx[35])
+				r_ec = ord(rx[36])*256+ord(rx[37])
+				mydata.append(("r_orp",r_orp))
+				mydata.append(("r_do",r_do))
+				mydata.append(("r_ec",r_ec))
+				##############DF_MQ8_H2##############
+				s_h2 = ord(rx[38])*256+ord(rx[39])
+				mydata.append(("s_h2",s_h2))
+				##############ME2_O3##############
+				s_o3 = ord(rx[40])*256+ord(rx[41])
+				mydata.append(("s_o3",s_o3))
+				##############ME2_O2##############
+				s_o2 = ord(rx[42])*256+ord(rx[43])
+				mydata.append(("s_o2",s_o2))
+				#################water_level#################################
+				water_level = ord(rx[52])
+				mydata.append(("water_level", water_level))
+				print mydata
+				mydata=urllib.urlencode(mydata)
+				req=urllib2.Request(path, mydata)
+				req.add_header('User-Agent','Magic Browser')
+				page=urllib2.urlopen(req).read()
+				print "case_command " + str(case_command) + ": OK"
+
+		except Exception, e:
+			print 'traceback.print_exc():'; traceback.print_exc()
+			print ("There is a problem please confirm")
+		validation=0
+
+print("Catch Data Now")
+while True :
+	Catch_Data()

+ 348 - 0
RS_GATEWAY/RS_G_All_Ver3.py

@@ -0,0 +1,348 @@
+#!/usr/bin/env python
+#-*- coding: utf-8 -*-
+#-*- coding: cp950 -*-
+
+import array,time,threading,mraa,serial,urllib2,urllib,os,os.path,requests,traceback   #How to install?? ----> pip install requests
+from BBIOServer import *
+pin_net = mraa.Pwm(19)#use J8 to be power light
+pin_net.enable(True)
+pin_net.write(1)
+
+
+if True :
+	Old_Led_Data =""
+	New_Led_Data =""
+	Old_MP3_Data =""
+	New_MP3_Data =""
+	Old_Switch_Data =""
+	New_Switch_Data =""
+	Old_Switch_Data =""
+	New_Switch_Data =""
+	Old_Fans_Data =""
+	New_Fans_Data =""
+
+	list_Old = 0
+	play_Old = 0
+	vol_Old = 0
+	rep_Old = 0
+
+	array_rx = 100
+	rx=[0x00]*array_rx
+	ser=serial.Serial('/dev/ttyS0',38400,timeout=1)
+	validation = 0
+
+	number = 1
+	s_humidity = 0
+	s_t_near_stem = 0
+	s_water_frequency = 0
+	s_c2h4 = 0
+	s_temp = 0
+	s_wind_flow = 0
+	s_o3 = 0
+	s_n2 = 0
+	s_mf = 0
+	s_o2 = 0
+	s_co2 = 0
+	s_vibration = 0
+	s_h2 = 0
+	s_uv = 0
+	r_humidity = 0
+	r_air_temp = 0
+	r_water_temp_1 = 0
+	r_water_temp_2 = 0
+	r_water_temp_3 = 0
+	r_orp = 0
+	r_nh4 = 0
+	r_ph = 0
+	r_co2 = 0
+	r_mf = 0
+	r_sonic = 0
+	r_turbidity = 0
+	r_no3 = 0
+	r_ec = 0
+	r_ed = 0
+	r_do = 0
+	r_magnetic_level = 0
+	r_no2 = 0
+	r_wind_flow = 0
+	r_fluorine = 0
+	r_electric_current = 0
+	r_root_t = 0
+	r_chlorine = 0
+	r_soil_temp = 0
+	r_soil_moisture = 0
+
+	path = "http://13.113.114.87/b/tofitolab.php"
+
+
+def Led_RGB_OPCL(x):
+	global Old_Led_Data
+	global New_Led_Data
+	LED_path = "http://13.113.114.87/b/rgb.php"
+	mydata=[('led_sw',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_SW =urllib2.urlopen(req).read()
+	Led_SW = int(Led_SW)
+	#====================================
+	mydata=[('led_r',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_R =urllib2.urlopen(req).read()
+	Led_R = int(Led_R)
+	#====================================
+	mydata=[('led_g',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_G =urllib2.urlopen(req).read()
+	Led_G = int(Led_G)
+	#====================================
+	mydata=[('led_b',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_B =urllib2.urlopen(req).read()
+	Led_B = int(Led_B)
+	#====================================
+	mydata=[('led_ir',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_IR =urllib2.urlopen(req).read()
+	Led_IR = int(Led_IR)
+	#====================================
+	mydata=[('led_uv',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_UV =urllib2.urlopen(req).read()
+	Led_UV = int(Led_UV)
+	#====================================
+	New_Led_Data = str(Led_R) +str(Led_G) +str(Led_B) +str(Led_SW) +str(Led_IR) +str(Led_UV)
+	if (Old_Led_Data != New_Led_Data):
+		print"detected differently  transmitting signals"
+		print Old_Led_Data
+		print New_Led_Data
+		if Led_SW == 0:
+			commandarray=[0xFF,0xFF,0xF1,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Led_Data = New_Led_Data
+		if Led_SW == 1:
+			commandarray=[0xFF,0xFF,0xF1,0x01,Led_R,Led_G,Led_B,Led_IR,Led_UV,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Led_Data = New_Led_Data
+		time.sleep(0.3)
+		print "R =" + str(Led_R) + " G ="+ str(Led_G)+" B ="+ str(Led_B) + " IR ="+str(Led_IR)+ " UV ="+str(Led_UV)+ " SW ="+str(Led_SW)
+
+def MP3_OPCL(x):
+	global Old_MP3_Data
+	global New_MP3_Data
+	global list_Old
+	global vol_Old
+	global play_Old
+	global rep_Old
+	MP3_Path = "http://13.113.114.87/b/music.php"
+	##----------------------------------
+	mydata=[('list',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	list =urllib2.urlopen(req).read()
+	list = int(list)
+	##----------------------------------
+	mydata=[('play',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	play =urllib2.urlopen(req).read()
+	play = int(play)
+	##----------------------------------
+	mydata=[('vol',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	vol =urllib2.urlopen(req).read()
+	vol = int(vol)
+	##----------------------------------
+	mydata=[('rep',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	rep =urllib2.urlopen(req).read()
+	rep = int(rep)
+	##----------------------------------
+	New_MP3_Data = str(list) +str(play) +str(vol) +str(rep)
+	if (Old_MP3_Data != New_MP3_Data):
+		print"detected differently transmitting signals"
+		print Old_MP3_Data
+		print New_MP3_Data
+		if (play_Old != play):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x01,play,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			play_Old = play
+			print"send play pause signal"
+		if (vol_Old != vol ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x02,vol,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			vol_Old = vol
+			print"send volume signal"
+		if (rep_Old != rep ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x03,rep,list,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			rep_Old = rep
+			print"send a loop signal"
+		if (list_Old != list ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x04,list,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			list_Old = list
+			print"send repertory signal"
+		print commandarray
+		Old_MP3_Data = New_MP3_Data
+		print "repertory =" + str(list) + " playback ="+ str(play)+"volume ="+ str(vol) + " redundant ="+str(rep)
+		time.sleep(0.3)
+		print"launched"
+
+
+def webcam_photo():
+	try:
+		print time.strftime('%m.%d.%Y-%H:%M:%S ')
+		camera_box_l = "http://13.113.114.87/b/cam/camera1_1.php"
+		#os.system('fswebcam -r 320x240 -d v4l2:/dev/video0 --save /tmp/camera_1.jpg')
+		os.system('wget http://192.168.1.173:8080/?action=snapshot -O /tmp/camera_1.jpg')
+		time.sleep(1)
+		files = {'file': open('/tmp/camera_1.jpg', 'rb')}
+		time.sleep(1)
+		r = requests.post(camera_box_l, files=files)
+		time.sleep(2)
+	except Exception, e:
+		print 'traceback.print_exc():'; traceback.print_exc()
+		print ("There is a problem  please confirm")
+
+def Led_Data_Blink():
+	for i in range(0,3):
+		pin_net.write(0)
+		time.sleep(0.1)
+		pin_net.write(1)
+		time.sleep(0.1)
+
+def Switch_Control_OPCL(x):
+	global Old_Switch_Data
+	global New_Switch_Data
+	Switch_path = "http://13.113.114.87/b/liquidtanks_switch.php"
+	mydata=[('fid',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(Switch_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Switch_Control =urllib2.urlopen(req).read()
+	New_Switch_Data = Switch_Control
+
+
+	if (Old_Switch_Data != New_Switch_Data):
+		print"detected differently  transmitting signals"
+		Switch_Control = Switch_Control.split("j")
+		#print "Switch Count = " + str(len(Switch_Control))
+		#print Switch_Control[0:]
+		if True :
+			commandarray=[0xFF,0xFF,0xF1,0x03,int(Switch_Control[0]),int(Switch_Control[1]),int(Switch_Control[2]),int(Switch_Control[3]),int(Switch_Control[4]),int(Switch_Control[5]),int(Switch_Control[6]),int(Switch_Control[7]),int(Switch_Control[8]),int(Switch_Control[9]),int(Switch_Control[10]),int(Switch_Control[11]),0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Switch_Data = New_Switch_Data
+		print time.strftime(' %m/%d/%Y'+' %H:%M:%S'+' add ok')
+		time.sleep(0.3)
+		print "Switch =" + str(New_Switch_Data)
+
+
+def Fans_Control_OPCL(x):
+	global Old_Fans_Data
+	global New_Fans_Data
+	Fans_path = "http://13.113.114.87/b/wind_flow.php"
+	mydata=[('wind',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(Fans_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Fans_Control =urllib2.urlopen(req).read()
+	Fans_Control = int(Fans_Control)
+	New_Fans_Data = Fans_Control
+	if (Old_Fans_Data != New_Fans_Data):
+		print"detected differently  transmitting signals"
+
+		if True :
+			print "OK"
+			commandarray=[0xFF,0xFF,0xF1,0x04,Fans_Control,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			print commandarray
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Fans_Data = New_Fans_Data
+		print time.strftime(' %m/%d/%Y'+' %H:%M:%S'+' add ok')
+		print "Fans value=" + str(Old_Fans_Data)
+
+def Catch_Data():
+				print "Go Case 02"
+				mydata = []
+				mydata.append(("number",1))
+				mydata.append(("type","norealtime"))
+				##############DHT22##############
+				mydata.append(("s_temp",2500))
+
+				mydata.append(("s_humidity",5000))
+				##############SHT22##############
+
+				mydata.append(("r_air_temp",2500))
+
+				mydata.append(("r_humidity",5000))
+				##############Cozir##############
+
+				mydata.append(("s_co2",0))
+				##############WaterTemp##############
+
+				mydata.append(("r_water_temp",0))
+
+				mydata.append(("r_water_temp_2",0))
+
+				mydata.append(("r_water_temp_3",0))
+				##############PH##############
+
+				mydata.append(("r_ph",764))
+				##############soil Humid##############
+
+				mydata.append(("r_soil_moisture",0))
+				##############Turbidity##############
+
+				mydata.append(("r_turbidity",0))
+				##############Uv##############
+
+				mydata.append(("s_uv",0))
+				##############sonic##############
+
+				mydata.append(("r_sonic",0))
+				##############ORP##############
+
+				mydata.append(("s_orp",0))
+				##############RS485##############
+
+				mydata.append(("r_orp",0))
+				mydata.append(("r_do",0))
+				mydata.append(("r_ec",0))
+				##############DF_MQ8_H2##############
+
+				mydata.append(("s_h2",0))
+				##############ME2_O3##############
+
+				mydata.append(("s_o3",0))
+				##############ME2_O2##############
+
+				mydata.append(("s_o2",0))
+				########################################################
+				print mydata
+				mydata=urllib.urlencode(mydata)
+				req=urllib2.Request(path, mydata)
+				req.add_header('User-Agent','Magic Browser')
+				page=urllib2.urlopen(req).read()
+				print "case_command " + str(2) + ": OK"
+
+
+
+print("Catch Data Now")
+while True :
+	Catch_Data()

+ 420 - 0
RS_GATEWAY/RS_G_control.py

@@ -0,0 +1,420 @@
+#!/usr/bin/env python
+#-*- coding: utf-8 -*-
+#-*- coding: cp950 -*-
+
+import array,time,threading,mraa,serial,urllib2,urllib,os,os.path,requests,traceback   #How to install?? ----> pip install requests
+from BBIOServer import *
+pin_net = mraa.Pwm(19)#使用J8來當作電源燈號
+pin_net.enable(True)
+pin_net.write(1)
+
+
+if True :
+	Old_Led_Data =""
+	New_Led_Data =""
+	Old_MP3_Data =""
+	New_MP3_Data =""
+	Old_Switch_Data =""
+	New_Switch_Data =""
+	Old_Switch_Data =""
+	New_Switch_Data =""
+	Old_Fans_Data =""
+	New_Fans_Data =""
+
+	list_Old = 0
+	play_Old = 0
+	vol_Old = 0
+	rep_Old = 0
+
+	array_rx = 100
+	rx=[0x00]*array_rx
+	ser=serial.Serial('/dev/ttyS0',38400,timeout=1)
+	validation = 0
+
+	number = 1
+	s_humidity = 0
+	s_t_near_stem = 0
+	s_water_frequency = 0
+	s_c2h4 = 0
+	s_temp = 0
+	s_wind_flow = 0
+	s_o3 = 0
+	s_n2 = 0
+	s_mf = 0
+	s_o2 = 0
+	s_co2 = 0
+	s_vibration = 0
+	s_h2 = 0
+	s_uv = 0
+	r_humidity = 0
+	r_air_temp = 0
+	r_water_temp_1 = 0
+	r_water_temp_2 = 0
+	r_water_temp_3 = 0
+	r_orp = 0
+	r_nh4 = 0
+	r_ph = 0
+	r_co2 = 0
+	r_mf = 0
+	r_sonic = 0
+	r_turbidity = 0
+	r_no3 = 0
+	r_ec = 0
+	r_ed = 0
+	r_do = 0
+	r_magnetic_level = 0
+	r_no2 = 0
+	r_wind_flow = 0
+	r_fluorine = 0
+	r_electric_current = 0
+	r_root_t = 0
+	r_chlorine = 0
+	r_soil_temp = 0
+	r_soil_moisture = 0
+
+	path = "http://13.113.114.87/b/tofitolab.php"
+	check_path = "http://13.113.114.87/b/tofitolab_isuse.php"
+	test_path = "http://52.195.10.119/b/tofitolab.php"
+	test_check_path = "http://52.195.10.119/b/tofitolab_isuse.php"
+
+def Led_RGB_OPCL(x):
+	global Old_Led_Data
+	global New_Led_Data
+	LED_path = "http://13.113.114.87/b/rgb.php"
+	mydata=[('led_sw',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_SW =urllib2.urlopen(req).read()
+	Led_SW = int(Led_SW)
+	#====================================
+	mydata=[('led_r',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_R =urllib2.urlopen(req).read()
+	Led_R = int(Led_R)
+	#====================================
+	mydata=[('led_g',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_G =urllib2.urlopen(req).read()
+	Led_G = int(Led_G)
+	#====================================
+	mydata=[('led_b',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_B =urllib2.urlopen(req).read()
+	Led_B = int(Led_B)
+	#====================================
+	mydata=[('led_ir',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_IR =urllib2.urlopen(req).read()
+	Led_IR = int(Led_IR)
+	#====================================
+	mydata=[('led_uv',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(LED_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Led_UV =urllib2.urlopen(req).read()
+	Led_UV = int(Led_UV)
+	#====================================
+	New_Led_Data = str(Led_R) +str(Led_G) +str(Led_B) +str(Led_SW) +str(Led_IR) +str(Led_UV)
+	if (Old_Led_Data != New_Led_Data):
+		print"偵測到不一樣,發射訊號"
+		print Old_Led_Data
+		print New_Led_Data
+		if Led_SW == 0:
+			commandarray=[0xFF,0xFF,0xF1,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Led_Data = New_Led_Data
+		if Led_SW == 1:
+			commandarray=[0xFF,0xFF,0xF1,0x01,Led_R,Led_G,Led_B,Led_IR,Led_UV,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Led_Data = New_Led_Data
+		time.sleep(0.3)
+		print "R =" + str(Led_R) + " G ="+ str(Led_G)+" B ="+ str(Led_B) + " IR ="+str(Led_IR)+ " UV ="+str(Led_UV)+ " SW ="+str(Led_SW)
+
+def MP3_OPCL(x):
+	global Old_MP3_Data
+	global New_MP3_Data
+	global list_Old
+	global vol_Old
+	global play_Old
+	global rep_Old
+	MP3_Path = "http://13.113.114.87/b/music.php"
+	##----------------------------------
+	mydata=[('list',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	list =urllib2.urlopen(req).read()
+	list = int(list)
+	##----------------------------------
+	mydata=[('play',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	play =urllib2.urlopen(req).read()
+	play = int(play)
+	##----------------------------------
+	mydata=[('vol',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	vol =urllib2.urlopen(req).read()
+	vol = int(vol)
+	##----------------------------------
+	mydata=[('rep',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(MP3_Path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	rep =urllib2.urlopen(req).read()
+	rep = int(rep)
+	##----------------------------------
+	New_MP3_Data = str(list) +str(play) +str(vol) +str(rep)
+	if (Old_MP3_Data != New_MP3_Data):
+		print"偵測到不一樣,發射訊號"
+		print Old_MP3_Data
+		print New_MP3_Data
+		if (play_Old != play):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x01,play,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			play_Old = play
+			print"發送播放暫停訊號"
+		if (vol_Old != vol ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x02,vol,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			vol_Old = vol
+			print"發送音量訊號"
+		if (rep_Old != rep ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x03,rep,list,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			rep_Old = rep
+			print"發送迴圈訊號"
+		if (list_Old != list ):
+			commandarray=[0xFF,0xFF,0xF1,0x02,0x04,list,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			list_Old = list
+			print"發送曲目訊號"
+		print commandarray
+		Old_MP3_Data = New_MP3_Data
+		print "曲目 =" + str(list) + " 撥放狀態 ="+ str(play)+" 音量 ="+ str(vol) + " 是否重複 ="+str(rep)
+		time.sleep(0.3)
+		print"發射完畢"
+
+
+def webcam_photo():
+	try:
+		print time.strftime('%m.%d.%Y-%H:%M:%S ')
+		camera_box_l = "http://13.113.114.87/b/cam/camera1_1.php"
+		#os.system('fswebcam -r 320x240 -d v4l2:/dev/video0 --save /tmp/camera_1.jpg')
+		os.system('wget http://192.168.1.173:8080/?action=snapshot -O /tmp/camera_1.jpg')
+		time.sleep(1)
+		files = {'file': open('/tmp/camera_1.jpg', 'rb')}
+		time.sleep(1)
+		r = requests.post(camera_box_l, files=files)
+		time.sleep(2)
+	except Exception, e:
+		print 'traceback.print_exc():'; traceback.print_exc()
+		print ("有問題,請確認")
+
+def Led_Data_Blink():
+	for i in range(0,3):
+		pin_net.write(0)
+		time.sleep(0.1)
+		pin_net.write(1)
+		time.sleep(0.1)
+
+def Switch_Control_OPCL(x):
+	global Old_Switch_Data
+	global New_Switch_Data
+	#Switch_path = "http://13.113.114.87/b/liquidtanks_switch.php"
+	#Switch_path = "http://13.113.114.87/b/pump_isuse.php"
+	Switch_path = "http://13.113.114.87/20200312/pump_isuse.php"
+	mydata=[('fid',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(Switch_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Switch_Control =urllib2.urlopen(req).read().decode("utf-8-sig").encode("utf-8")
+	New_Switch_Data = Switch_Control
+
+
+	if (Old_Switch_Data != New_Switch_Data):
+		print"偵測到不一樣,發射訊號"
+		Switch_Control = Switch_Control.split(",")
+		print(Switch_Control)
+		#print "Switch Count = " + str(len(Switch_Control))
+		#print Switch_Control[0:]
+		if True :
+			commandarray=[0xFF,0xFF,0xF1,0x03,int(Switch_Control[0]),int(Switch_Control[1]),int(Switch_Control[2]),int(Switch_Control[3]),int(Switch_Control[4]),int(Switch_Control[5]),int(Switch_Control[6]),int(Switch_Control[7]),int(Switch_Control[8]),int(Switch_Control[9]),int(Switch_Control[10]),int(Switch_Control[11]),0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Switch_Data = New_Switch_Data
+		print time.strftime(' %m/%d/%Y'+' %H:%M:%S'+' add ok')
+		time.sleep(0.3)
+		print "Switch =" + str(New_Switch_Data)
+
+
+def Fans_Control_OPCL(x):
+	global Old_Fans_Data
+	global New_Fans_Data
+	#Fans_path = "http://13.113.114.87/b/wind_flow.php"
+	Fans_path = "http://13.113.114.87/b/fan_isuse.php"
+	mydata=[('wind',x)]
+	mydata=urllib.urlencode(mydata)
+	req=urllib2.Request(Fans_path, mydata)
+	req.add_header('User-Agent','Magic Browser')
+	Fans_Control =urllib2.urlopen(req).read().decode("utf-8-sig").encode("utf-8")
+	New_Fans_Data = Fans_Control
+	if (Old_Fans_Data != New_Fans_Data):
+		print"偵測到不一樣,發射訊號"
+		Fans_Control = Fans_Control.split(",")
+		if True :
+			print "OK"
+			commandarray=[0xFF,0xFF,0xF1,0x04,int(Fans_Control[0]),int(Fans_Control[1]),0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+			print commandarray
+			ser.write(array.array('B',commandarray).tostring())
+			Old_Fans_Data = New_Fans_Data
+		print time.strftime(' %m/%d/%Y'+' %H:%M:%S'+' add ok')
+		print "Fans value=" + str(Old_Fans_Data)
+
+def Catch_Data():
+	global validation
+	global validation
+	commandarray = [0xFF, 0xFF, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+					0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D]
+	print commandarray
+	ser.write(array.array('B', commandarray).tostring())
+	time.sleep(15)
+	commandarray = [0xFF,0xFF,0x01,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D]
+	print commandarray
+	ser.write(array.array('B', commandarray).tostring())
+	time.sleep(1)
+	if ser.inWaiting():
+		rx[0]=ser.read()
+		if rx[0]=='\xff':
+			validation +=1
+			rx[1]=ser.read()
+			if rx[1]=='\xff':
+				print "go updatta command old"
+				validation +=1
+				rx[2:array_rx]=ser.read(array_rx-2)############################要測試
+				if rx[array_rx-1]=='\x0d':############################要測試
+					print "Rx[final] == 0D"
+					validation +=1
+				else:
+					validation=0 
+			else:
+				validation=0
+		else:
+			validation = 0
+	if validation ==3:
+		number= ord(rx[2])
+		case_command= ord(rx[3])
+		try:
+			if case_command ==02:
+				print "Go Case 02"
+				mydata = []
+				mydata.append(("number",number))
+				mydata.append(("type","norealtime"))
+				##############DHT22##############
+				s_temp = ord(rx[4])*256+ord(rx[5])
+				mydata.append(("s_temp",s_temp))
+				s_humidity = ord(rx[6])*256+ord(rx[7])
+				mydata.append(("s_humidity",s_humidity))
+				##############SHT22##############
+				r_air_temp = ord(rx[8])*256+ord(rx[9])
+				mydata.append(("r_air_temp",r_air_temp))
+				r_humidity = ord(rx[10])*256+ord(rx[11])
+				mydata.append(("r_humidity",r_humidity))
+				##############Cozir##############
+				s_co2= ord(rx[12])*256+ord(rx[13])
+				mydata.append(("s_co2",s_co2))
+				##############WaterTemp##############
+				r_water_temp_1 = ord(rx[14])*256+ord(rx[15]) 
+				mydata.append(("r_water_temp",r_water_temp_1))
+				r_water_temp_2 = ord(rx[16])*256+ord(rx[17])
+				mydata.append(("r_water_temp_2",r_water_temp_2))
+				r_water_temp_3 = ord(rx[18])*256+ord(rx[19])
+				mydata.append(("r_water_temp_3",r_water_temp_3))
+				##############PH##############
+				r_ph = ord(rx[20])*256+ord(rx[21])
+				mydata.append(("r_ph",r_ph))
+				##############soil Humid##############
+				r_soil_moisture = ord(rx[22])*256+ord(rx[23])
+				mydata.append(("r_soil_moisture",r_soil_moisture))
+				##############Turbidity##############
+				r_turbidity = ord(rx[24])*256+ord(rx[25])
+				mydata.append(("r_turbidity",r_turbidity))
+				##############Uv##############
+				s_uv = ord(rx[26])*256+ord(rx[27])
+				mydata.append(("s_uv",s_uv))
+				##############sonic##############
+				r_sonic = ord(rx[28])*256+ord(rx[29])
+				mydata.append(("r_sonic",r_sonic))
+				##############ORP##############
+				Df_Orp = ord(rx[30])*256+ord(rx[31])
+				mydata.append(("s_orp",Df_Orp))
+				##############RS485##############
+				r_orp = ord(rx[32])*256+ord(rx[33])
+				r_do = ord(rx[34])*256+ord(rx[35])
+				r_ec = ord(rx[36])*256+ord(rx[37])
+				mydata.append(("r_orp",r_orp))
+				mydata.append(("r_do",r_do))
+				mydata.append(("r_ec",r_ec))
+				##############DF_MQ8_H2##############
+				s_h2 = ord(rx[38])*256+ord(rx[39])
+				mydata.append(("s_h2",s_h2))
+				##############ME2_O3##############
+				s_o3 = ord(rx[40])*256+ord(rx[41])
+				mydata.append(("s_o3",s_o3))
+				##############ME2_O2##############
+				s_o2 = ord(rx[42])*256+ord(rx[43])
+				mydata.append(("s_o2",s_o2))
+				########################################################
+				weight_1 = ord(rx[44]) * 256 + ord(rx[45])
+				weight_2 = ord(rx[46]) * 256 + ord(rx[47])
+				weight_3 = ord(rx[48]) * 256 + ord(rx[49])
+				weight_4 = ord(rx[50]) * 256 + ord(rx[51])
+				mydata.append(("weight_1", weight_1))
+				mydata.append(("weight_2", weight_2))
+				mydata.append(("weight_3", weight_3))
+				mydata.append(("weight_4", weight_4))
+				################water_level##################################
+				r_water_level = ord(rx[52])
+				mydata.append(("r_water_level", r_water_level))
+				################Flexible_Piezo##################################
+				r_touch = ord(rx[53]) * 256 + ord(rx[54])
+				mydata.append(("r_touch", r_touch))
+				################Df_piezo##################################
+				s_vibration = ord(rx[55]) * 256 + ord(rx[56])
+				mydata.append(("s_vibration", s_vibration))
+				##################################################
+				print mydata
+				mydata=urllib.urlencode(mydata)
+				req=urllib2.Request(path, mydata)
+				req.add_header('User-Agent','Magic Browser')
+				page=urllib2.urlopen(req).read()
+				print "case_command " + str(case_command) + ": OK"
+				Led_Data_Blink()
+				#webcam_photo()
+		except Exception, e:
+			print 'traceback.print_exc():'; traceback.print_exc()
+			print ("有問題,請確認")
+		validation=0
+
+
+
+
+
+print("Catch Data Now")
+while True :
+	Switch_Control_OPCL(1)
+	print "Switch_Control_OPCL"
+	#time.sleep(1)
+	#Catch_Data()
+	#time.sleep(60)