Illustration: how the ESP-cloud serve your application!!

costaud
Posts: 138
Joined: Fri Oct 24, 2014 7:40 pm

Illustration: how the ESP-cloud serve your application!!

Postby costaud » Thu Dec 04, 2014 12:06 am

esp_iot_sdk_v0.9.1_multi-sensor_141204.rar
(645.86 KiB) Downloaded 686 times

get_multi-sensor_data.rar
(1.01 KiB) Downloaded 486 times


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 )
7.png
7.png (6.61 KiB) Viewed 10887 times


2)config the demo to sensor and humiture_sub_device
8.png
8.png (5.53 KiB) Viewed 10887 times


3)define the deep sleep time (defaultly 30s,that means the device will wake up and send data every 30 seconds)
9.png
9.png (8.22 KiB) Viewed 10887 times


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
1.png
1.png (10.28 KiB) Viewed 10887 times


2)Choose a new product
2.png
2.png (36.88 KiB) Viewed 10887 times


3)Set your device name product type and name, whatever you want. Creat!
3.png
3.png (27.8 KiB) Viewed 10887 times


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!!
4.png
4.png (33.61 KiB) Viewed 10887 times

5.png
5.png (23.5 KiB) Viewed 10887 times


step3:download master device key and firmware to the device .
1)Copy the master device key and save as a binary file.
6.png
6.png (3.29 KiB) Viewed 10887 times


2)download the firmware and devicekey
13.png
13.png (20.16 KiB) Viewed 10887 times


step4: config the device to your AP.
1)connect the device softap and send json config command.
10.png
10.png (34.01 KiB) Viewed 10887 times


2)After the device finishing registration ,you can send a sleep command (or change the firmware to sleep automatically)
14.png
14.png (19.94 KiB) Viewed 10887 times

11.png
11.png (4.26 KiB) Viewed 10887 times


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.
12.png
12.png (68.49 KiB) Viewed 10887 times


click the "share" button , there would be a datapoint chart which shows every detail of the upload data.
15.png
15.png (50.97 KiB) Viewed 10887 times


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]

koliqi
Posts: 1
Joined: Thu Nov 06, 2014 1:51 am

Re: Illustration: how the ESP-cloud serve your application!!

Postby koliqi » Thu Dec 04, 2014 2:47 am

Thank you for detailed IoT presentation. Two questions
step2:create a device and get device master key on the cloud side( iot.espressif.com)

does that mean you have created iot.espressif.com english version of iot.espressif.cn ?
2)download the firmware and devicekey
Image

Here is picture of ESP_FLASH_DOWNLOAD_TOOL_V0.9.3.1. This software was published but I can't get it on Downloads section. Did you removed it from public access or maybe I am looking on wrong place?

koliqi

costaud
Posts: 138
Joined: Fri Oct 24, 2014 7:40 pm

Re: Illustration: how the ESP-cloud serve your application!!

Postby costaud » Thu Dec 04, 2014 3:15 am

koliqi wrote:Thank you for detailed IoT presentation. Two questions
step2:create a device and get device master key on the cloud side( iot.espressif.com)

does that mean you have created iot.espressif.com english version of iot.espressif.cn ?
2)download the firmware and devicekey

Here is picture of ESP_FLASH_DOWNLOAD_TOOL_V0.9.3.1. This software was published but I can't get it on Downloads section. Did you removed it from public access or maybe I am looking on wrong place?

koliqi


my mistake ,the url is :
iot.espressif.cn

download tool :
viewtopic.php?f=7&t=25

okmine
Posts: 1
Joined: Thu Jan 15, 2015 10:20 pm

Re: Illustration: how the ESP-cloud serve your application!!

Postby okmine » Fri Jan 23, 2015 4:37 pm

very good example. I still have one question relate this application:
How to use the RPC example from the iot.espressif.com?
I click the button and and set command always return fail to "{"status":404,"nonce":350361931,"message":"remote device is disconnect or busy"}". but from 8266 end point, there is nothing message receive from the user_esp_platform_recv_cb() and never jump into this callback.

I ever thought this relate to the deep sleep mode as default. actually, I've comment out the deep sleep mode and make the 8266 never disconnect and re-connect with host.

Expect your reply!
Thanks!

Her Majesty
Posts: 186
Joined: Mon Oct 27, 2014 11:09 am

Re: Illustration: how the ESP-cloud serve your application!!

Postby Her Majesty » Mon Jan 26, 2015 5:31 pm

"status":404 is not a problem , it is because your ESP8266 won't answer a response for the user-define RPC message .. if you add response for the RPC message , it will be succeed to status 200..

But your user_esp_platform_recv_cb() receives nothing .. this is a problem ... mine is fine .. did you download the correct master_device_key.bin (@0x3E000) to your ESP8266 board ?

Amit
Posts: 3
Joined: Fri Feb 27, 2015 12:22 pm

Re: Illustration: how the ESP-cloud serve your application!!

Postby Amit » Mon Mar 02, 2015 9:16 pm

Is there a way to pass a String to ESP8266 from cloud server? It seems Data Stream only takes Integer or floating point Values.

ESP_Faye
Posts: 1623
Joined: Mon Oct 27, 2014 11:08 am

Re: Illustration: how the ESP-cloud serve your application!!

Postby ESP_Faye » Fri Mar 06, 2015 11:40 am

Hi, amit,

Yes, you can.

Please have a try with this mailbox APIs @http://iot.espressif.cn/#/api-en/#api-mbox

clairehouqq
Posts: 2
Joined: Fri Aug 25, 2017 3:21 pm

Re: Illustration: how the ESP-cloud serve your application!!

Postby clairehouqq » Fri Aug 25, 2017 4:11 pm

where to send command in this picuture? Is it some kind of tool or online page?
Attachments
10.png
send json config command picture

Who is online

Users browsing this forum: No registered users and 1 guest