![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
STM32F103C8T6 a demo with esp8266 pust onenet
Dependencies: cJSON_lib Common_lib EdpKit_lib DHT ESP8266 wifi_example
main.cpp@2:1dbc3aa8ae3a, 2017-03-29 (annotated)
- Committer:
- TaylorGy
- Date:
- Wed Mar 29 03:14:41 2017 +0000
- Revision:
- 2:1dbc3aa8ae3a
- Parent:
- 0:b887535f68bf
- Child:
- 3:296161f9baf9
Beta Version V1.01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TaylorGy | 2:1dbc3aa8ae3a | 1 | /************************************************************/ |
TaylorGy | 2:1dbc3aa8ae3a | 2 | /* (C) 2016 Beijing ARM Accelerator Technology Co., Ltd. */ |
TaylorGy | 2:1dbc3aa8ae3a | 3 | /* Description: Demo for ASC Platform. */ |
TaylorGy | 2:1dbc3aa8ae3a | 4 | /* Performed an example for getting data form Sensors, */ |
TaylorGy | 2:1dbc3aa8ae3a | 5 | /* then send data to OneNet Cloud by using EDP protocol */ |
TaylorGy | 2:1dbc3aa8ae3a | 6 | /* Author: ss.pan */ |
TaylorGy | 2:1dbc3aa8ae3a | 7 | /* Version: 1.01 */ |
TaylorGy | 2:1dbc3aa8ae3a | 8 | /* Date: 2017-03-28 */ |
TaylorGy | 2:1dbc3aa8ae3a | 9 | /************************************************************/ |
TaylorGy | 2:1dbc3aa8ae3a | 10 | #include "mbed.h" |
TaylorGy | 2:1dbc3aa8ae3a | 11 | #include "wifi_example.h" |
TaylorGy | 2:1dbc3aa8ae3a | 12 | #include "driver_mbed_TH02.h" |
TaylorGy | 2:1dbc3aa8ae3a | 13 | #include <driver_mbed_HP20x.h> |
TaylorGy | 2:1dbc3aa8ae3a | 14 | #include <driver_mbed_KalmanFilter.h> |
group-ESP8266 | 0:b887535f68bf | 15 | |
TaylorGy | 2:1dbc3aa8ae3a | 16 | unsigned char ret = 0; |
group-ESP8266 | 0:b887535f68bf | 17 | |
TaylorGy | 2:1dbc3aa8ae3a | 18 | KalmanFilter p_filter; //Kalman filter for pressure |
TaylorGy | 2:1dbc3aa8ae3a | 19 | KalmanFilter a_filter; //Kalman filter for altitude |
group-ESP8266 | 0:b887535f68bf | 20 | |
TaylorGy | 2:1dbc3aa8ae3a | 21 | float temperature = -999.999; |
TaylorGy | 2:1dbc3aa8ae3a | 22 | float humidity = -999.999; |
TaylorGy | 2:1dbc3aa8ae3a | 23 | float pressure = -999.999; |
TaylorGy | 2:1dbc3aa8ae3a | 24 | float pressure_filtered = -999.999; |
TaylorGy | 2:1dbc3aa8ae3a | 25 | float altitude = -999.999; |
TaylorGy | 2:1dbc3aa8ae3a | 26 | float altitude_filtered = -999.999; |
group-ESP8266 | 0:b887535f68bf | 27 | |
TaylorGy | 2:1dbc3aa8ae3a | 28 | void getSensorDat(void); |
TaylorGy | 2:1dbc3aa8ae3a | 29 | |
TaylorGy | 2:1dbc3aa8ae3a | 30 | /** |
TaylorGy | 2:1dbc3aa8ae3a | 31 | * @brief main |
TaylorGy | 2:1dbc3aa8ae3a | 32 | **/ |
TaylorGy | 2:1dbc3aa8ae3a | 33 | int main() |
group-ESP8266 | 0:b887535f68bf | 34 | { |
TaylorGy | 2:1dbc3aa8ae3a | 35 | connectInit(); |
TaylorGy | 2:1dbc3aa8ae3a | 36 | devLink(DEVICEID,APIKEY); |
TaylorGy | 2:1dbc3aa8ae3a | 37 | while(1) { |
TaylorGy | 2:1dbc3aa8ae3a | 38 | getSensorDat(); |
TaylorGy | 2:1dbc3aa8ae3a | 39 | if(!checkSocketStatus()) { |
TaylorGy | 2:1dbc3aa8ae3a | 40 | sendJsonDat("humidity ", humidity); |
TaylorGy | 2:1dbc3aa8ae3a | 41 | wait_ms(500); |
TaylorGy | 2:1dbc3aa8ae3a | 42 | sendJsonDat("temperature", temperature); |
TaylorGy | 2:1dbc3aa8ae3a | 43 | wait_ms(500); |
TaylorGy | 2:1dbc3aa8ae3a | 44 | sendJsonDat("pressure", pressure_filtered); |
TaylorGy | 2:1dbc3aa8ae3a | 45 | wait_ms(500); |
TaylorGy | 2:1dbc3aa8ae3a | 46 | sendJsonDat("altitude", altitude_filtered); |
TaylorGy | 2:1dbc3aa8ae3a | 47 | wait_ms(500); |
TaylorGy | 2:1dbc3aa8ae3a | 48 | } |
group-ESP8266 | 0:b887535f68bf | 49 | } |
group-ESP8266 | 0:b887535f68bf | 50 | } |
group-ESP8266 | 0:b887535f68bf | 51 | |
TaylorGy | 2:1dbc3aa8ae3a | 52 | /** |
TaylorGy | 2:1dbc3aa8ae3a | 53 | * @brief get sensor data |
TaylorGy | 2:1dbc3aa8ae3a | 54 | **/ |
TaylorGy | 2:1dbc3aa8ae3a | 55 | void getSensorDat(void) |
group-ESP8266 | 0:b887535f68bf | 56 | { |
TaylorGy | 2:1dbc3aa8ae3a | 57 | int ret; |
TaylorGy | 2:1dbc3aa8ae3a | 58 | temperature = myTH02.ReadTemperature(); |
TaylorGy | 2:1dbc3aa8ae3a | 59 | humidity = myTH02.ReadHumidity(); |
TaylorGy | 2:1dbc3aa8ae3a | 60 | wait_ms(50); |
TaylorGy | 2:1dbc3aa8ae3a | 61 | HP20x.begin(); |
TaylorGy | 2:1dbc3aa8ae3a | 62 | wait_ms(100); |
group-ESP8266 | 0:b887535f68bf | 63 | |
TaylorGy | 2:1dbc3aa8ae3a | 64 | ret = HP20x.isAvailable(); |
TaylorGy | 2:1dbc3aa8ae3a | 65 | if(OK_HP20X_DEV == ret) { |
TaylorGy | 2:1dbc3aa8ae3a | 66 | long p_data = HP20x.ReadPressure(); |
TaylorGy | 2:1dbc3aa8ae3a | 67 | pressure = p_data/100.0f; |
TaylorGy | 2:1dbc3aa8ae3a | 68 | pressure_filtered = p_filter.Filter(pressure); |
group-ESP8266 | 0:b887535f68bf | 69 | |
TaylorGy | 2:1dbc3aa8ae3a | 70 | long a_data = HP20x.ReadAltitude(); |
TaylorGy | 2:1dbc3aa8ae3a | 71 | altitude = a_data/100.0f; |
TaylorGy | 2:1dbc3aa8ae3a | 72 | altitude_filtered = a_filter.Filter(altitude); |
group-ESP8266 | 0:b887535f68bf | 73 | } |
TaylorGy | 2:1dbc3aa8ae3a | 74 | } |