Skip to content

Instantly share code, notes, and snippets.

@chrowe
Last active October 19, 2017 04:10
Show Gist options
  • Save chrowe/4fc8e789db3898d4d0aa9d63ac957768 to your computer and use it in GitHub Desktop.
Save chrowe/4fc8e789db3898d4d0aa9d63ac957768 to your computer and use it in GitHub Desktop.
Campbell output
# Run on Windows with C:\Python27\python.exe Desktop/cr1000.py
import requests
import time
from BeautifulSoup import BeautifulSoup
url = "http://192.168.0.102/?command=dataquery&uri=dl:SOIL_MET&format=html&mode=most-recent&p1"
def getdata():
logger_data = [] # creat a variable to store data
response = requests.get(url) # bring the above url in to play
html = response.content # returns html version of the page you just requested
soup = BeautifulSoup(html)
table = soup.find('table') #finds the data table in the html code
for i in table.findAll('td'): # this for loop will iterate through as many <td> there are in the table
data = i.text.replace('td', '') #replaces the <td> part of the html code
logger_data.append(data) # after every interation a new value will be added
return logger_data #returns all the values from the table
# for example logger_data[0] will return the timestamp
# logger_data[1] will return the rec number of the logger and so on till you have all you data
while True:
try:
data = getdata()
print data
time.sleep(60)
except:
print "error"
[
{
"name": "batt_volt_Min",
"type": "xsd:float",
"units": "V",
"process": "Min",
"settable": false,
"value": 0,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "VWC_cs",
"type": "xsd:float",
"units": "m^3/m^3",
"process": "Smp",
"settable": false,
"value": 0.079,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "EC_cs",
"type": "xsd:float",
"units": "dS/m",
"process": "Smp",
"settable": false,
"value": 0.009,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "TSoil_cs",
"type": "xsd:float",
"units": "deg C",
"process": "Smp",
"settable": false,
"value": 11.4,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "Eb",
"type": "xsd:float",
"process": "Smp",
"settable": false,
"value": 9.48,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "TSoil_d",
"type": "xsd:float",
"units": "Deg_C",
"process": "Smp",
"settable": false,
"value": 12.7,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "VWC_d",
"type": "xsd:float",
"units": "m^3/m^3",
"process": "Smp",
"settable": false,
"value": 0.178,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "SoilTemp(1)",
"type": "xsd:float",
"units": "deg_C",
"process": "Smp",
"settable": false,
"value": 34.28,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "SoilTemp(2)",
"type": "xsd:float",
"units": "deg_C",
"process": "Smp",
"settable": false,
"value": 13.56,
"timestamp": "2017-10-18T21:30:00"
},
{
"name": "SoilTemp(3)",
"type": "xsd:float",
"units": "deg_C",
"process": "Smp",
"settable": false,
"value": 14.74,
"timestamp": "2017-10-18T21:30:00"
}
]
{
"head":{
"transaction":0,
"signature":10757,
"environment":{
"station_name":"9686",
"table_name":"wind",
"model":"CR3000",
"serial_no":"9686",
"os_version":"CR3000.Std.30.01",
"prog_name":"CPU:WolfesNeck_son5.CR3"
},
"fields":[
{
"name":"Ts_Avg",
"type":"xsd:float",
"units":"C",
"process":"Avg",
"settable":false
},
{
"name":"Ts_Std",
"type":"xsd:float",
"units":"C",
"process":"Std",
"settable":false
},
{
"name":"Ux_Avg",
"type":"xsd:float",
"units":"m/s",
"process":"Avg",
"settable":false
},
{
"name":"Ux_Std",
"type":"xsd:float",
"units":"m/s",
"process":"Std",
"settable":false
},
{
"name":"Uy_Avg",
"type":"xsd:float",
"units":"m/s",
"process":"Avg",
"settable":false
},
{
"name":"Uy_Std",
"type":"xsd:float",
"units":"m/s",
"process":"Std",
"settable":false
},
{
"name":"Uz_Avg",
"type":"xsd:float",
"units":"m/s",
"process":"Avg",
"settable":false
},
{
"name":"Uz_Std",
"type":"xsd:float",
"units":"m/s",
"process":"Std",
"settable":false
},
{
"name":"wnd_dir_compass",
"type":"xsd:float",
"units":"degrees",
"process":"Smp",
"settable":false
},
{
"name":"wnd_dir_csat3",
"type":"xsd:float",
"units":"degrees",
"process":"Smp",
"settable":false
},
{
"name":"wnd_spd",
"type":"xsd:float",
"units":"m/s",
"process":"Smp",
"settable":false
},
{
"name":"rslt_wnd_spd",
"type":"xsd:float",
"units":"m/s",
"process":"Smp",
"settable":false
},
{
"name":"std_wnd_dir",
"type":"xsd:float",
"units":"degrees",
"process":"Smp",
"settable":false
},
{
"name":"n_Tot",
"type":"xsd:float",
"units":"samples",
"process":"Tot",
"settable":false
},
{
"name":"csat_warnings",
"type":"xsd:float",
"units":"samples",
"process":"Tot",
"settable":false
},
{
"name":"del_T_f_Tot",
"type":"xsd:float",
"units":"samples",
"process":"Tot",
"settable":false
},
{
"name":"sig_lck_f_Tot",
"type":"xsd:float",
"units":"samples",
"process":"Tot",
"settable":false
},
{
"name":"amp_h_f_Tot",
"type":"xsd:float",
"units":"samples",
"process":"Tot",
"settable":false
},
{
"name":"amp_l_f_Tot",
"type":"xsd:float",
"units":"samples",
"process":"Tot",
"settable":false
},
{
"name":"panel_temp_Avg",
"type":"xsd:float",
"units":"C",
"process":"Avg",
"settable":false
},
{
"name":"batt_volt_Avg",
"type":"xsd:float",
"units":"V",
"process":"Avg",
"settable":false
}
]
},
"data":[
{
"time":"2017-09-27T14:30:00",
"no":4566,
"vals":[
25.3329,
0.8341268,
-1.126773,
1.068205,
-0.9328261,
0.8259126,
-0.4216249,
0.4533992,
95.37958,
-140.3796,
1.847895,
1.462804,
36.97672,
18000,
0,
0,
0,
0,
0,
34.76551,
0
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment