After we set up the firmware in the chip side, now we can use the esp cloud service to do something wonderful.
See -->http://bbs.espressif.com/viewtopic.php?f=15&t=56
and see ==> viewtopic.php?f=15&t=31
Firstly , this is an illustration to show you how to collect sensor data and upload to the cloud server, moreover, how to get the data and process.
step1: use the sdk sensor demo directly and do some change:
1)change the Datastream name( must accord with the datastream name on the server )
2)config the demo to sensor and humiture_sub_device
3)define the deep sleep time (defaultly 30s,that means the device will wake up and send data every 30 seconds)
step2:create a device and get device master key on the cloud side( iot.espressif.cn)
1)Sign up , login and create a product and define your own device
2)Choose a new product
3)Set your device name product type and name, whatever you want. Creat!
4)Then you have a master device key and now continue to create a datastream format.
In this demo ,we have 4 different sensor( temperature,huminity,pressure,brightness),but we can still define a 5 dimension data format. ( Attention : datastream name must be accord with the name in the sdk sensor showed in pic1.
Create!!
step3:download master device key and firmware to the device .
1)Copy the master device key and save as a binary file.
2)download the firmware and devicekey
step4: config the device to your AP.
1)connect the device softap and send json config command.
2)After the device finishing registration ,you can send a sleep command (or change the firmware to sleep automatically)
Then the device will send data and get into deep sleep mode in circles.
step5: Enjoy!!!
You can see every post event on the esp cloud side and see the datas in chart.
click the "share" button , there would be a datapoint chart which shows every detail of the upload data.
After all ,you can use this python script to collect all the specified data you want.
get_sensor_data.py:
Use the get_test_data function ,
key: replace your own device key
start: set the start time of data
end: set the end time of data,
devCnt : the data point number you want
offset : the page offset from the last data page.
get_test_data(devCnt=100,key='7233680dfbcdf6318f808a998d02bc5d9dee0703',start='2014-12-03 00:00:00',end='2014-12-03 23:59:59',offset=0)
Code: Select all
from datetime import datetime
import os
import binascii
import string
import httplib
import urllib2
import json
DATETIME_FORMAT = '%Y%m%d-%H-%M-%S'
now = datetime.now()
dir_datetime = now.strftime(DATETIME_FORMAT)
def get_test_data(devCnt=10,key='26484cd14129a0c64ed1bf9608fec6cabb0fd0c9',start='',end='',offset=0):
devices_count =devCnt
devKey = key
start_time = start
end_time = end
offset = offset
host = 'iot.espressif.cn'
headers = {'Host': host, 'User-Agent': 'Mozilla', 'Accept': '*/*', 'Authorization': 'token %s'%devKey}
devices_serial = ['{}']*devices_count
print 'devices_serial: ',devices_serial
params = None#'{"debugs": ['+ ','.join(devices_serial) + ']}'
#print 'params : ',params
if start_time=='':
path = '/v1/datastreams/sensor_data_point/datapoints/?row_count=%d'%devices_count
elif offset == 0:
path = '/v1/datastreams/sensor_data_point/datapoints/?row_count=%d&start=%s&end=%s'%(devices_count ,start_time,end_time)
else:
path = '/v1/datastreams/sensor_data_point/datapoints/?row_count=%d&start=%s&end=%s&offset=%d'%(devices_count ,start_time,end_time,offset)
conn = httplib.HTTPConnection(host, port=80)
conn.request("GET", path, params, headers)
response = conn.getresponse()
data = response.read()
conn.close()
total_data_dict = json.loads(data)
time_list=[]
tem_list=[]
hum_list=[]
pres_list=[]
lumen_list=[]
for dict_tmp in total_data_dict["datapoints"]:
time_list.append( dict_tmp["updated"] )
tem_list.append( dict_tmp['x'])
hum_list.append( dict_tmp['y'])
pres_list.append( dict_tmp['z'])
lumen_list.append( dict_tmp['k'])
print "time: ",time_list
print "temperature : 'C\n",tem_list
print "r-huminity : % \n",hum_list
print "pressure : hPa \n",pres_list
print "luminance : Lx \n",lumen_list
if __name__ == '__main__':
get_test_data(devCnt=50,key='7233680dfbcdf6318f808a998d02bc5d9dee0703',start='2014-12-03 00:00:00',end='2014-12-03 23:59:59',offset=0)
result:
Code: Select all
time: [u'2014-12-03 23:40:14', u'2014-12-03 23:39:44', u'2014-12-03 23:39:13', u'2014-12-03 23:38:43', u'2014-12-03 23:38:13', u'2014-12-03 23:37:42', u'2014-12-03 23:37:12', u'2014-12-03 23:36:41', u'2014-12-03 23:36:11', u'2014-12-03 23:35:40', u'2014-12-03 23:35:11', u'2014-12-03 23:34:39', u'2014-12-03 23:34:09', u'2014-12-03 23:33:38', u'2014-12-03 23:33:08', u'2014-12-03 23:32:37', u'2014-12-03 23:32:02', u'2014-12-03 23:31:32', u'2014-12-03 23:31:01', u'2014-12-03 23:30:31', u'2014-12-03 23:29:56', u'2014-12-03 23:29:25', u'2014-12-03 23:28:55', u'2014-12-03 23:28:25', u'2014-12-03 23:27:54', u'2014-12-03 23:27:23', u'2014-12-03 23:26:53', u'2014-12-03 23:26:23', u'2014-12-03 23:25:52', u'2014-12-03 23:25:22', u'2014-12-03 23:24:51', u'2014-12-03 23:24:20', u'2014-12-03 23:23:50', u'2014-12-03 23:23:19', u'2014-12-03 23:22:49', u'2014-12-03 23:22:19', u'2014-12-03 23:21:48', u'2014-12-03 23:21:18', u'2014-12-03 23:20:47', u'2014-12-03 23:20:17', u'2014-12-03 23:19:47', u'2014-1
2-03 23:19:17', u'2014-12-03 23:18:45', u'2014-12-03 23:18:15', u'2014-12-03 23:17:45', u'2014-12-03 23:17:14', u'2014-12-03 23:16:44', u'2014-12-03 23:16:13', u'2014-12-03 23:15:43', u'2014-12-03 23:15:12']
temperature : 'C
[20.300000000000001, 20.300000000000001, 20.34, 20.449999999999999, 20.469999999999999, 20.530000000000001, 20.579999999999998, 20.800000000000001, 20.690000000000001, 20.57, 20.309999999999999, 20.27, 20.25, 20.280000000000001, 20.280000000000001, 20.280000000000001, 20.390000000000001, 20.379999999999999, 20.41, 20.34, 20.379999999999999, 20.32, 20.41, 20.100000000000001, 20.030000000000001, 20.02, 20.030000000000001, 20.059999999999999, 20.129999999999999, 20.140000000000001, 19.989999999999998, 19.870000000000001, 19.84, 19.84, 19.879999999999999, 19.879999999999999, 19.949999999999999, 19.98, 20.02, 20.07, 20.129999999999999, 20.18, 20.199999999999999, 20.23, 20.100000000000001, 20.07, 19.940000000000001, 19.870000000000001, 19.870000000000001, 19.870000000000001]
r-huminity : %
[61.159999999999997, 61.200000000000003, 61.200000000000003, 61.240000000000002, 61.240000000000002, 61.240000000000002, 61.140000000000001, 60.840000000000003, 61.280000000000001, 61.520000000000003, 61.469999999999999, 61.689999999999998, 61.670000000000002, 61.859999999999999, 61.829999999999998, 61.969999999999999, 61.710000000000001, 61.520000000000003, 61.280000000000001, 61.890000000000001, 61.780000000000001, 61.829999999999998, 61.560000000000002, 62.119999999999997, 61.780000000000001, 61.57, 60.68, 60.030000000000001, 59.829999999999998, 59.869999999999997, 60.119999999999997, 60.170000000000002, 60.189999999999998, 60.090000000000003, 59.869999999999997, 59.869999999999997, 59.729999999999997, 59.579999999999998, 59.460000000000001, 59.359999999999999, 59.270000000000003, 59.119999999999997, 59.130000000000003, 59.090000000000003, 59.25, 59.280000000000001, 59.420000000000002, 59.43, 59.350000000000001, 59.240000000000002]
pressure : hPa
[1024.79, 1024.73, 1024.6099999999999, 1024.53, 1024.3499999999999, 1024.51, 1024.45, 1024.4100000000001, 1024.3699999999999, 1024.3299999999999, 1024.3499999999999, 1024.4100000000001, 1024.55, 1024.49, 1024.5899999999999, 1024.6099999999999, 1024.71, 1024.71, 1024.8299999999999, 1024.9100000000001, 1024.9100000000001, 1025.0899999999999, 1025.1500000000001, 1025.1700000000001, 1025.2, 1025.26, 1025.4200000000001, 1025.3599999999999, 1025.48, 1025.5599999999999, 1025.5599999999999, 1025.5599999999999, 1025.6400000000001, 1025.7, 1025.7, 1025.78, 1025.78, 1025.74, 1025.9200000000001, 1025.8599999999999, 1025.8399999999999, 1025.9200000000001, 1025.9200000000001, 1025.9200000000001, 1025.9400000000001, 1025.8800000000001, 1025.9200000000001, 1025.8800000000001, 1026.0799999999999, 1025.96]
luminance : Lx
[907.0, 907.0, 887.0, 910.0, 903.0, 893.0, 897.0, 917.0, 917.0, 910.0, 917.0, 873.0, 907.0, 913.0, 920.0, 907.0, 920.0, 920.0, 930.0, 923.0, 920.0, 913.0, 917.0, 930.0, 930.0, 943.0, 947.0, 957.0, 883.0, 883.0, 893.0, 900.0, 900.0, 883.0, 897.0, 883.0, 887.0, 890.0, 883.0, 883.0, 883.0, 900.0, 893.0, 883.0, 883.0, 890.0, 883.0, 897.0, 887.0, 880.0]