Advertisement
Guest User

Untitled

a guest
Oct 29th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. import json
  2. from urllib.request import urlopen
  3. import requests
  4. from ControllerState import ControllerState, FertilizationProgram, InyectionProgram, IrrigationProgram,AlarmConfig
  5. URL_SERVER = 'http://emiliozelione2018.pythonanywhere.com/'
  6. USERNAME = "Prueba1"
  7. PASSWORD = "goldfinger"
  8.  
  9.  
  10.  
  11. def sendSetFertilization():
  12. Val= [12,13,14,15,16,17,18,19,2.5,7.0]
  13. response = requests.get("http://emiliozelione2018.pythonanywhere.com/requests?set_fertilization"
  14. "&username=Prueba1&password=goldfinger&program=&1value_1="+str(Val[0])+
  15. "&value_2="+str(Val[1])+"&value_3="+str(Val[2])+"&value_4="+str(Val[3])+
  16. "&value_5="+str(Val[4])+"&value_6="+str(Val[5])+"&value_7="+str(Val[6])+
  17. "&value_8="+str(Val[7])+"&ec="+str(Val[8])+"&ph="+str(Val[9]))
  18. response = requests.get("http://emiliozelione2018.pythonanywhere.com/requests?all&username=Prueba1&password=goldfinger")
  19. #dataJson = response.json()
  20. #print (dataJson)
  21.  
  22.  
  23. def sendSetIrrigation():
  24. Val = [3,3,2,3,4,5,6,7,8,9,10,11,12,33,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
  25. response = requests.get("http://emiliozelione2018.pythonanywhere.com/requests?set_irrigation"
  26. "&username=Prueba1&password=goldfinger&program="+str(Val[1])+"&who=1"
  27. "&units="+str(Val[1])+"&water_before_1="+str(Val[2])+"&water_before_2="+str(Val[3])+
  28. "&water_after_1="+str(Val[4])+"&water_after_2="+str(Val[5])+"&water_total_1="+str(Val[6])+
  29. "&water_total_2="+str(Val[7])+"&kicks="+str(Val[8])+"&fertilization_program="+str(Val[9])+
  30. "&condition_program="+str(Val[10])+"&time_start_1="+str(Val[11])+"&time_start_2="+str(Val[11])+
  31. "&time_between_1="+str(Val[12])+"&time_between_2="+str(Val[13])+"&valves=1,5,4,3")
  32.  
  33. response = requests.get("http://emiliozelione2018.pythonanywhere.com/requests?all&username=Prueba1&password=goldfinger")
  34. dataJson = response.json()
  35. print (dataJson)
  36.  
  37.  
  38. def fetchJson():
  39. response = requests.get(URL_SERVER + 'requests?all&username=' +
  40. USERNAME +'&password=' +PASSWORD)
  41. dataJson = response.json()
  42. return(dataJson)
  43.  
  44. def fetchLastUpdate():
  45. response = requests.get(
  46. URL_SERVER +
  47. 'requests?updated_when&username=' +
  48. USERNAME +
  49. '&password=' +
  50. PASSWORD)
  51. dataJson = response.json()
  52. return(dataJson['update'])
  53.  
  54. def checkLogin():
  55. response = requests.get(
  56. URL_SERVER +
  57. 'login?username=' +
  58. USERNAME +
  59. '&password=' +
  60. PASSWORD)
  61. dataJson = response.json()
  62. return(dataJson['ok'])
  63.  
  64.  
  65.  
  66.  
  67.  
  68. def sendSetConfigAlarms():
  69. cA = cs.alarm_config
  70. print(cA.deviation_warning_max_error_flow)
  71. response = requests.get(URL_SERVER + '/requests?set_config_alarms&username=' + USERNAME +'&password=' +PASSWORD+
  72. "&who=1&deviation_warning_max_error_flow="+str(30)+ "&function_alarm_ec_ph_dangerous=" + str(1)+
  73. "&delay_alarms_ec_ph_secs=" + str(50)+ "&delay_alarm_ph_dangerous_secs=" + str(90)+
  74. "&delay_alarm_ec_dangerous_secs="+ str(60)+ "&delay_alarm_high_pressure_kg=" + str(15)+
  75. "&delay_alarm_low_pressure_secs="+str(90)+ "&delay_alarm_flow_secs=" +str(60)+
  76. "&max_diff_warning_error_ec="+str(1)+ "&max_diff_warning_error_ph=" +str(1)+
  77. "&max_deviation_under_ph="+str(2)+ "&max_deviation_over_ec="+str(2)+
  78. "&level_alarm_high_pressure_kg=" +str(4)+ "&level_alarm_low_pressure_kg="+str(1)+
  79. "&function_alarm_fertilizer_discontinued=" +str(30)+ "&function_alarm_high_pressure="+str(1)+
  80. "&function_alarm_dangerous_flow=" +str(1)+ "&function_alarm_no_fertilization="+str(0)+
  81. "&function_alarm_no_water=" +str(1)+ "&pulses_fertilizer_no_control="+str(50)+
  82. "&pulses_needs_fertilizer=" +str(30)+ "&max_seconds_between_water_pulses="+str(90)+
  83. "&over_dangerous_flow_percentage=" +str(70)+ "&delay_secs_if_diff_ec_more_1="+str(30)+
  84. "&delay_secs_if_diff_ec_more_05=" +str(20)+ "&delay_secs_if_diff_ec_more_03="+str(15)+
  85. "&coefficient_correction_ec_more_1=" +str(30)+ "&coefficient_correction_ec_more_05="+str(20)+
  86. "&coefficient_correction_ec_more_03=" +str(15)+ "&delay_secs_if_diff_ph_more_1="+str(30)+
  87. "&delay_secs_if_diff_ph_more_05=" +str(20)+ "&delay_secs_if_diff_ph_more_03="+str(20)+
  88. "&coefficient_correction_ph_more_1=" +str(30)+ "&coefficient_correction_ph_more_05="+str(25)+
  89. "&coefficient_correction_ph_more_03="+str(15)+ "&secs_first_ec_correction="+str(65)+
  90. "&secs_first_ph_correction="+str(65))
  91. dataJson = response.json()
  92. print("QUE TIRA EL JSON DE CONFIG ALARMAS" + str(dataJson))
  93. return(dataJson)
  94.  
  95.  
  96. correctLogin = False
  97. cs = ControllerState()
  98.  
  99. if correctLogin == False:
  100. correctLogin = checkLogin()
  101. if correctLogin:
  102. print("login ok")
  103. else:
  104. print("login error")
  105.  
  106. data = fetchJson()
  107. cs.load_from_json(data)
  108. #sendSetConfigAlarms()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement