Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix esp-idf compatibility, add support for basic auth, add support fo… #52

Open
wants to merge 213 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
213 commits
Select commit Hold shift + click to select a range
1a1773d
json-based configuration and web control panel (incl thingspeak)
kglowacki Feb 14, 2017
9093d27
mask wifi password
kglowacki Feb 15, 2017
f012856
enable web server in station mode
kglowacki Feb 15, 2017
3b4dd5e
new bme driver
kglowacki Feb 15, 2017
b75c5f3
detect bmp/bme, but pressure for bmp is wrong
kglowacki Feb 15, 2017
e5c34e1
bme280 compatible driver + humidity measurement
kglowacki Feb 16, 2017
b8be5fd
change default AP IP to 192.168.1.1
kglowacki Feb 16, 2017
af875cb
fix led being 'too green'
kglowacki Feb 16, 2017
ef64d7c
working example
kglowacki Feb 18, 2017
b767bf8
working awsiot GET_SHADOW
kglowacki Feb 18, 2017
190a536
config for awsiot
kglowacki Feb 18, 2017
ca48be7
post works, but ssl_free fails
kglowacki Feb 22, 2017
716399a
working awsiot spike
kglowacki Feb 23, 2017
f6ae8cf
basic AWS IoT rest client
kglowacki Feb 24, 2017
4b89c94
new api + doc
kglowacki Feb 24, 2017
28905e5
screenshot updated
kglowacki Feb 24, 2017
a0ea306
add more logs
kglowacki Mar 14, 2017
0f192c9
fix crash during soft reboot
kglowacki Mar 14, 2017
cbf6fa9
improved stability
kglowacki Mar 16, 2017
c4cb8b6
changelog updated
kglowacki Mar 16, 2017
ee3f0ea
refactor bmx driver
kglowacki Mar 16, 2017
5fdd855
handle two env sensors
kglowacki Mar 17, 2017
070ef41
refactor pm to simplify config and flow
kglowacki Mar 17, 2017
2bb613c
two bme280 sensors tested.
kglowacki Mar 17, 2017
5998261
support external fan and heater
kglowacki Mar 17, 2017
37e2626
add main_task stack size note
kglowacki Mar 17, 2017
28d2da5
working prototype
kglowacki Mar 25, 2017
ef24f0c
support for two pm sensors
kglowacki Mar 28, 2017
758a402
various improvements
Aug 6, 2017
979f17c
update docs
Sep 6, 2017
692d53a
update ESP-IDF to 2.1
kglowacki Sep 6, 2017
5b52043
track firmware version
kglowacki Sep 7, 2017
8dd0a78
fix config save issue
kglowacki Sep 10, 2017
d35a938
clean config api
kglowacki Sep 10, 2017
77f4709
display version in control panel
kglowacki Sep 10, 2017
88fb607
0.4.3 OTA updates
kglowacki Sep 16, 2017
aede20e
draft
kglowacki Sep 19, 2017
965f2d0
fix ota tests
kglowacki Sep 21, 2017
df712c5
bmx280 tests
kglowacki Sep 21, 2017
8c9289f
add Unity test app
kglowacki Sep 22, 2017
43b303c
fix #21
kglowacki Sep 22, 2017
c6c4dc9
enable jenkins build (fix #4)
kglowacki Sep 23, 2017
96aa410
use github as OTA server
kglowacki Sep 23, 2017
d2fc249
rollback to old ota location
kglowacki Sep 23, 2017
3dc62e5
use sdkconfig.defaults for jenkins build
kglowacki Sep 23, 2017
3654941
another jenkins fix
kglowacki Sep 23, 2017
36c8839
one more jenkins fix
kglowacki Sep 23, 2017
b98bb05
one more jenkins fix
kglowacki Sep 23, 2017
2345014
fix #24
kglowacki Sep 24, 2017
57e3a68
refactor pm_meter
kglowacki Oct 1, 2017
7f03ae3
configurable tty port
kglowacki Oct 2, 2017
494b2f9
jenkins tty
kglowacki Oct 2, 2017
deeef24
jenkins tty
kglowacki Oct 2, 2017
0809f4e
jenkins fix test
kglowacki Oct 2, 2017
9ec5128
fix for SH
kglowacki Oct 2, 2017
08af632
fix jenkins
kglowacki Oct 2, 2017
ecd921d
fix jenkins
kglowacki Oct 2, 2017
d34b14b
use persistent mapping for usb devices
kglowacki Oct 3, 2017
4843c71
fix memory leaks
kglowacki Oct 3, 2017
2343dac
fix security issue
kglowacki Oct 4, 2017
bbb7dff
configurable OTA interval (fix #28)
kglowacki Oct 4, 2017
8ae8735
fix for memory leaks in ota
kglowacki Oct 4, 2017
a74d5b4
stable wifi
kglowacki Oct 5, 2017
947cea0
new partitions and bugfixes
kglowacki Oct 5, 2017
bec5209
jenkins fix
kglowacki Oct 5, 2017
b3337d0
fixes
kglowacki Oct 6, 2017
e8a32b6
try to recover from 0x4c SSL error
kglowacki Oct 6, 2017
c65606b
small fixes
kglowacki Oct 6, 2017
03b3032
small fixes
kglowacki Oct 6, 2017
4750dd8
tests and fixes for SSL stack
kglowacki Oct 6, 2017
e94e6bf
disable http when network is not available
kglowacki Oct 6, 2017
6950add
jenkins - do not flash
kglowacki Oct 6, 2017
1e4e49f
silence make output
kglowacki Oct 6, 2017
912f0bc
switch to stable v2.1 esp-idf
kglowacki Oct 7, 2017
b6bb383
fix wifi event handling to work with sdk v2.1
kglowacki Oct 7, 2017
7dbb76a
skip unstalbe test
kglowacki Oct 7, 2017
c0c35f5
clean log
kglowacki Oct 7, 2017
24b4fa0
cleanup logs
kglowacki Oct 7, 2017
dbc319b
clean warnings
kglowacki Oct 7, 2017
2463e71
disable log colors for tests (cleaner jenkins log)
kglowacki Oct 7, 2017
338772f
prefix all modules to avoid name collision with esp modules
kglowacki Oct 7, 2017
a3289b9
option to reset to factory firmware, fix #40
kglowacki Oct 8, 2017
0aa3305
Release 1.0.0
kglowacki Oct 8, 2017
1d061f6
update changelog for 1.0.0
kglowacki Oct 8, 2017
e817964
reboot after crash, fix #43
kglowacki Oct 9, 2017
df464cd
describe firmware uplaod, fix #16
kglowacki Oct 9, 2017
6eb1c5a
formatting
kglowacki Oct 9, 2017
376ffee
formatting
kglowacki Oct 9, 2017
044d1cb
typo
kglowacki Oct 9, 2017
b686e08
improve mem logging
kglowacki Oct 9, 2017
83a0c07
improv mem logging
kglowacki Oct 9, 2017
305b556
store coredump in flash
kglowacki Oct 12, 2017
b76dc38
fix defaults
kglowacki Oct 18, 2017
35dc54b
reduce flash freq (related to #42)
kglowacki Oct 18, 2017
8bbc309
bump to 1.2.0
kglowacki Oct 18, 2017
82b231d
jenkins fix
kglowacki Oct 18, 2017
9af82e9
disable pmsensor before and after unit tests
kglowacki Oct 25, 2017
1bd8f2e
Seems MarkDown is picky about the whitespace...
codepainters Oct 31, 2017
b3972b0
Merge pull request #48 from codepainters/master
kglowacki Nov 5, 2017
e5b342e
Fix esp-idf compatibility, add support for basic auth, add support fo…
Jan 3, 2018
c45cee7
Fix esp-idf compatibility, add support for basic auth, add support fo…
Jan 3, 2018
b8420d4
add temperature from mh-z19, make rgb led configurable, add hexdump f…
Jan 4, 2018
3206b39
add temperature from mh-z19, make rgb led configurable, add hexdump f…
Jan 4, 2018
f96160a
reset MH-Z19 sensor and check values for sanity
Jan 4, 2018
e78fd26
reset MH-Z19 sensor and check values for sanity
Jan 4, 2018
f8c16d8
fix description for altitude
Jan 4, 2018
fa0909c
fix description for altitude
Jan 4, 2018
d24de15
setup sensor with ABC logic on and range of 2000ppm
Jan 4, 2018
3b23844
setup sensor with ABC logic on and range of 2000ppm
Jan 4, 2018
298a9c1
add configurable offsets for temperature and humidity
Jan 4, 2018
16026ec
add configurable offsets for temperature and humidity
Jan 4, 2018
10319b7
baycom:add fix type prefix, fix offset value types
Jan 4, 2018
f29ac64
baycom:add fix type prefix, fix offset value types
Jan 4, 2018
504b2c2
remove mh-z19 setup
Jan 4, 2018
b83b059
remove mh-z19 setup
Jan 4, 2018
0919d73
add display support
Jan 7, 2018
06ff034
add display support
Jan 7, 2018
e3be997
add /status output for webserver
Jan 7, 2018
c0be2e0
add /status output for webserver
Jan 7, 2018
40a705f
add live view of current data on web page
Jan 7, 2018
24305e3
add live view of current data on web page
Jan 7, 2018
0d47326
fix reload time
Jan 7, 2018
d966141
fix reload time
Jan 7, 2018
5c9ca35
add version and uptime in status display
Jan 7, 2018
76111af
add version and uptime in status display
Jan 7, 2018
aa4de88
use sealevel pressure in web frontend and on display
Jan 8, 2018
02baa33
use sealevel pressure in web frontend and on display
Jan 8, 2018
96b39fd
re enable range check for mh-z19 and add http user agent with version
Jan 9, 2018
8fdb04c
re enable range check for mh-z19 and add http user agent with version
Jan 9, 2018
ab27cac
allow publishing without dust meter
Jan 9, 2018
2e374f8
allow publishing without dust meter
Jan 9, 2018
a26281d
bump version to 1.3.5
Jan 9, 2018
4d1a917
bump version to 1.3.5
Jan 9, 2018
16761d0
improve status view
Jan 9, 2018
d4ff9b4
improve status view
Jan 9, 2018
685e83c
correct humidity according to temperature offset
Jan 9, 2018
ffb4405
correct humidity according to temperature offset
Jan 9, 2018
6461b2d
remove unused test tree
Jan 10, 2018
cb69e9e
remove unused test tree
Jan 10, 2018
97d059f
Config option for button logic
Jan 10, 2018
115511f
Config option for button logic
Jan 10, 2018
0c778cb
add distance metering
Jan 13, 2018
af0efbc
add distance metering
Jan 13, 2018
01ce5d1
improve Kconfig files/menus, generalize hc-sr04 code
Jan 13, 2018
ee5f521
improve Kconfig files/menus, generalize hc-sr04 code
Jan 13, 2018
e77a999
finalized distance metering
Jan 13, 2018
5680229
finalized distance metering
Jan 13, 2018
fa21c7b
add seconds ago to web page, better validation of distance
Jan 14, 2018
dd1f1ee
add seconds ago to web page, better validation of distance
Jan 14, 2018
0f0c102
add SMA gnerator, currently used for CO2
Jan 22, 2018
6e00b75
add SMA gnerator, currently used for CO2
Jan 22, 2018
bffabaf
fix sma
Jan 22, 2018
cfb45a6
fix sma
Jan 22, 2018
f53b5d5
fix sma
Jan 22, 2018
93484e3
fix sma
Jan 22, 2018
1dff3e2
fix wifi reconnection
Jan 23, 2018
09a7b48
fix wifi reconnection
Jan 23, 2018
d162057
change co2 measurement interval
Jan 24, 2018
b6f0824
change co2 measurement interval
Jan 24, 2018
0091549
fix basic auth
Jan 30, 2018
43dcd43
fix basic auth
Jan 30, 2018
c77adbc
add sma filter to distance
Feb 3, 2018
318623b
add sma filter to distance
Feb 3, 2018
9acd57b
sma over distance, re enable mh-z19 abc
Feb 4, 2018
1c320ea
sma over distance, re enable mh-z19 abc
Feb 4, 2018
9025e40
add generic gpio support
Feb 11, 2018
6520969
add generic gpio support
Feb 11, 2018
261d38b
add GPIO support, bump version to 1.4.0
Apr 29, 2018
1fb342f
add GPIO support, bump version to 1.4.0
Apr 29, 2018
cf08fa5
use 64bit timestamps of localtime, bump version to 1.4.1
Apr 29, 2018
b279010
use 64bit timestamps of localtime, bump version to 1.4.1
Apr 29, 2018
261b787
change defaults, add pcnt code to gpio, fix race condition in GPIO-IS…
Apr 30, 2018
a499c8f
change defaults, add pcnt code to gpio, fix race condition in GPIO-IS…
Apr 30, 2018
b91df23
Update README.md
baycom Apr 30, 2018
59d99db
Update README.md
baycom Apr 30, 2018
152db17
add http header to answer, version 1.4.4
May 1, 2018
2180322
add http header to answer, version 1.4.4
May 1, 2018
ddd8ce0
fix counter, version 1.4.6
May 1, 2018
4814a51
fix counter, version 1.4.6
May 1, 2018
231b3f0
add GPOlastVal to status, version 1.4.10
May 5, 2018
968aa88
add GPOlastVal to status, version 1.4.10
May 5, 2018
308d7ee
add GPOlastVal to status, version 1.4.10
May 5, 2018
999894c
set subsystems to disabled by default
May 7, 2018
55c981f
set subsystems to disabled by default
May 7, 2018
270501b
set subsystems to disabled by default
May 7, 2018
1dd44c7
set subsystems to disabled by default
May 7, 2018
913e729
set subsystems to disabled by default
May 7, 2018
e6ad69b
set subsystems to disabled by default
May 7, 2018
2564142
set subsystems to disabled by default
May 7, 2018
4331db7
Merge branch 'master' of https://github.com/baycom/sensor-esp32
May 7, 2018
84b374d
Merge branch 'master' of https://github.com/baycom/sensor-esp32
May 7, 2018
197adfb
Merge branch 'master' of https://github.com/baycom/sensor-esp32
May 7, 2018
cdcacf5
Merge branch 'master' of https://github.com/baycom/sensor-esp32
May 7, 2018
c2f9fb4
set subsystems to disabled by default
May 7, 2018
5a3faf2
set subsystems to disabled by default
May 7, 2018
8df9c0a
Merge branch 'master' of https://github.com/baycom/sensor-esp32
May 7, 2018
7b42fdf
fix index.html, version 1.4.11
May 7, 2018
31718c2
make status-url relative
May 8, 2018
f3144d0
add GPOtriggerLength, version 1.4.14
May 8, 2018
6028ff4
remove compiler warnings, add GPICountDelta to hw_gpio, version 1.4.18
May 11, 2018
7e4bf04
add GPIO udp server, bump version to 1.4.20
Jul 12, 2018
126ae8f
whitespace changes, fix deprecation waring
Jul 12, 2018
ec82a4c
parse multiple xml tags of same type
Jul 12, 2018
94939cb
add wifi watchdog
Jul 17, 2018
45d129c
fix inaccessible web frontend by reboot (quick and dirty hack) - bug …
Sep 20, 2018
b2a7d23
use webserver of esp-idf instead of mongoose
Oct 5, 2018
ff30c2b
minor fixes, bump version to 1.4.25
Oct 5, 2018
fda5c2c
Update README.md
baycom Oct 6, 2018
f56db20
bring code up to date with current sdk
Jun 9, 2019
986c6e9
Merge branch 'master' of https://github.com/baycom/sensor-esp32
Jun 9, 2019
1ce0692
fix wifi init
Jun 9, 2019
c04e95d
fix lwip max sockets
Jun 9, 2019
12ac080
disable wifi power saver
Jun 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
# OpenAirProject AirQuality / Dust Meter
# OpenAirProject AirQuality / Dust / CO2 / Distance - Meter + GPIO and OLED Display

The current implementation of this code contains support for additional
hardware like:

- CO2 sensor: MH-Z19 (can be calibrated via

http://<sensor>/trigger?func=calibrate

- OLED display: SSD 1306

- Ultrasonic distance sensor: HC SR04

- GPIO: 4 ports in with counter via

http://<sensor>/status

- GPIO 4 ports out with trigger via

http://<sensor>/trigger?delay=<0|ms>&gpio=<0-3>&value=<0|1>

Further these changes and additions have been made:

- FIX WIFI instability

- Add Device ID to DHCP-Client-Hostname

- Show collected values in realtime on web frontend

- Add disable / enable single hardware components via web frontend

- Add configurable offsets for humidity, temperature and altitude via web frontend

- Add HTTP-GET publisher with basic auth

- Some Pinouts have been changed:

- - Button is now on Pin 0 (button on ESP32 board), low active (configurable)

- - RGB LED has been reduced to channel blue on Pin 2 (LED on ESP32 board, configurable)

- - Pins for heater and fan have been set to unused (-1) by default

- - No need for RTS/CTS pin assignment on RS232 ports

## The following description is outdated ##

## Features

Expand Down
20 changes: 7 additions & 13 deletions components/oap-aws/awsiot.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "oap_common.h"
#include "oap_debug.h"
#include "oap_publisher.h"
#include "oap_storage.h"
#include "bootwifi.h"

static const char *TAG = "awsiot";
Expand Down Expand Up @@ -102,9 +103,9 @@ static esp_err_t awsiot_rest_post(oap_measurement_t* meas, oap_sensor_config_t *
if (meas->env) {
cJSON* weather = cJSON_CreateObject();
cJSON_AddItemToObject(results, "weather", weather);
cJSON_AddNumberToObject(weather, "temp", meas->env->temp);
cJSON_AddNumberToObject(weather, "pressure", meas->env->pressure);
cJSON_AddNumberToObject(weather, "humidity", meas->env->humidity);
cJSON_AddNumberToObject(weather, "temp", meas->env->bmx280.temp);
cJSON_AddNumberToObject(weather, "pressure", meas->env->bmx280.pressure);
cJSON_AddNumberToObject(weather, "humidity", meas->env->bmx280.humidity);
cJSON_AddNumberToObject(weather, "sensor", meas->env->sensor_idx);
} else {
cJSON_AddNullToObject(results, "weather");
Expand All @@ -113,9 +114,9 @@ static esp_err_t awsiot_rest_post(oap_measurement_t* meas, oap_sensor_config_t *
if (meas->env_int) {
cJSON* internal = cJSON_CreateObject();
cJSON_AddItemToObject(results, "internal", internal);
cJSON_AddNumberToObject(internal, "temp", meas->env_int->temp);
cJSON_AddNumberToObject(internal, "pressure", meas->env_int->pressure);
cJSON_AddNumberToObject(internal, "humidity", meas->env_int->humidity);
cJSON_AddNumberToObject(internal, "temp", meas->env_int->bmx280.temp);
cJSON_AddNumberToObject(internal, "pressure", meas->env_int->bmx280.pressure);
cJSON_AddNumberToObject(internal, "humidity", meas->env_int->bmx280.humidity);
cJSON_AddNumberToObject(internal, "sensor", meas->env_int->sensor_idx);
} else {
cJSON_AddNullToObject(results, "internal");
Expand All @@ -132,13 +133,6 @@ static esp_err_t awsiot_rest_post(oap_measurement_t* meas, oap_sensor_config_t *
return res;
}

static void set_config_str_field(char** field, char* value) {
if (*field) {
free(*field);
}
*field = str_dup(value);
}

static esp_err_t awsiot_configure(cJSON* awsiot) {
awsiot_config.configured = 0;

Expand Down
26 changes: 20 additions & 6 deletions components/oap-common/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"password": "",
"ip": "",
"gw": "",
"netmask": ""
"netmask": "",
"sensorId": ""
},
"thingspeak": {
"enabled": 0,
Expand All @@ -20,15 +21,28 @@
},
"sensor" : {
"config" : {
"indoor" : 0,
"pms_enabled" : 0,
"bmx280_enabled": 0,
"mhz19_enabled" : 0,
"hcsr04_enabled": 0,
"ssd1306_enabled": 0,
"gpio_enabled" : 1,
"indoor" : 1,
"led" : 1,
"fan" : 1,
"heater" : 1,
"fan" : 0,
"heater" : 0,
"measTime" : 60,
"warmUpTime": 30,
"measInterval": 300,
"test" : 0,
"measStrategy": 0
"measStrategy" : 0,
"altitude" : 573,
"tempOffset" : 0,
"humidityOffset" : 0
}
},
"http_get_publisher": {
"enabled": 0,
"url": "https://<myurl>/pushvals.cgi"
}
}
}
16 changes: 15 additions & 1 deletion components/oap-common/include/oap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"

#include "esp_request.h"

//to silence eclipse errors
typedef unsigned short uint16_t;

Expand All @@ -47,6 +49,14 @@ void oap_reboot(char* cause);
long oap_epoch_sec();
long oap_epoch_sec_valid();

typedef struct {
double *data;
size_t size;
unsigned int lastpos;
double sum;
} sma_data_t;


//from esp-arduino

/**
Expand All @@ -67,5 +77,9 @@ uint32_t micros();
uint32_t millis();
void delay(uint32_t);
void delayMicroseconds(uint32_t us);

void set_gpio(uint8_t gpio, uint8_t enabled);
void configure_gpio(uint8_t gpio);
void req_set_user_agent(request_t* req);
double sma_generator (sma_data_t *sma, double value);
int64_t get_time_millis();
#endif /* MAIN_COMMON_COMMON_H_ */
24 changes: 24 additions & 0 deletions components/oap-common/include/oap_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@
#include "oap_data_pm.h"
#include "oap_data_env.h"

// FIXME this stuff has to be generalized
typedef struct {
pm_data_t* pm;
pm_data_t* pm_aux;
env_data_t* env;
env_data_t* env_int;
env_data_t* co2;
env_data_t* distance1;
env_data_t* distance2;
env_data_t* gpio1;
env_data_t* gpio2;
env_data_t* gpio3;
env_data_t* gpio4;
long int local_time;
} oap_measurement_t;

Expand All @@ -45,7 +53,23 @@ typedef struct {
int meas_interval;
int meas_strategy; //interval, continuos, etc
int test;
int altitude;
int tempOffset;
int humidityOffset;
int pms_enabled;
int hcsr04_enabled;
int bmx280_enabled;
int gpio_enabled;
int ssd1306_enabled;
int mhz19_enabled;
int gpio_udp_enabled;
} oap_sensor_config_t;

typedef struct {
env_data_t env_data;
long timestamp;
} env_data_record_t;

extern env_data_record_t last_env_data[];

#endif /* COMPONENTS_OAP_COMMON_INCLUDE_OAP_DATA_H_ */
38 changes: 35 additions & 3 deletions components/oap-common/include/oap_data_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,43 @@
#ifndef COMPONENTS_OAP_COMMON_INCLUDE_OAP_DATA_ENV_H_
#define COMPONENTS_OAP_COMMON_INCLUDE_OAP_DATA_ENV_H_

typedef enum {
sensor_bmx280 = 0,
sensor_mhz19,
sensor_hcsr04,
sensor_gpio
} sensor_type_t;

typedef struct {
double temp;
double pressure;
double humidity;
uint8_t sensor_idx;
sensor_type_t sensor_type;

union {
struct {
double temp;
double pressure;
double sealevel;
double humidity;
uint32_t altitude;
} bmx280;
struct {
double temp;
uint32_t co2;
} mhz19;
struct {
uint32_t distance;
} hcsr04;
struct {
int val;
int64_t GPIlastLow;
int64_t GPIlastHigh;
int64_t GPICounter;
int64_t GPICountDelta;
int64_t GPOlastOut;
int64_t GPOtriggerLength;
int8_t GPOlastVal;
} gpio;
};
} env_data_t;

#endif /* COMPONENTS_OAP_COMMON_INCLUDE_OAP_DATA_ENV_H_ */
1 change: 1 addition & 0 deletions components/oap-common/include/oap_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ size_t avg_free_heap_size();
void log_task_stack(const char* task);
void log_heap_size(const char* msg);
void reduce_heap_size_to(size_t size);
void hexdump(const unsigned char *data, int len);
14 changes: 14 additions & 0 deletions components/oap-common/include/oap_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
#include <stdlib.h>
#include "cJSON.h"

/**
* @brief get a mac based system name
*/
void get_generic_name(char *name);

/**
* @brief get allocated string from string
*/
void set_config_str_field(char** field, char* value);

/**
* @brief initialise config
*/
void storage_clean();

/**
* @brief initialise storage and config
Expand Down
4 changes: 2 additions & 2 deletions components/oap-common/include/oap_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include "esp_err.h"

#define OAP_VER_MAJOR 1
#define OAP_VER_MINOR 2
#define OAP_VER_PATCH 0
#define OAP_VER_MINOR 4
#define OAP_VER_PATCH 29

typedef struct {
uint8_t major;
Expand Down
43 changes: 42 additions & 1 deletion components/oap-common/oap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
#include "esp_log.h"
#include "esp_system.h"
#include "freertos/task.h"
#include "driver/gpio.h"

static const long FEB22_2017 = 1487795557;
static const char *TAG="oap";

static int _reboot_in_progress = 0;
int is_reboot_in_progress() {
return _reboot_in_progress;
}
void oap_reboot(char* cause) {
ESP_LOGW("oap", "REBOOT ON DEMAND (%s)", cause);
ESP_LOGW(TAG, "REBOOT ON DEMAND (%s)", cause);
_reboot_in_progress = 1;
esp_restart();
}
Expand Down Expand Up @@ -105,4 +107,43 @@ void IRAM_ATTR delayMicroseconds(uint32_t us)
}
}

void set_gpio(uint8_t gpio, uint8_t enabled) {
if (gpio > 0) {
ESP_LOGD(TAG, "set pin %d => %d", gpio, enabled);
gpio_set_level(gpio, enabled);
}
}

void configure_gpio(uint8_t gpio) {
if (gpio > 0) {
ESP_LOGD(TAG, "configure pin %d as output", gpio);
gpio_pad_select_gpio(gpio);
ESP_ERROR_CHECK(gpio_set_direction(gpio, GPIO_MODE_OUTPUT));
ESP_ERROR_CHECK(gpio_set_pull_mode(gpio, GPIO_PULLDOWN_ONLY));
}
}

void req_set_user_agent(request_t* req) {
char agent[80];
sprintf(agent, "User-Agent: OAP-ESP32/%s", oap_version_str());
req_setopt(req, REQ_SET_HEADER, agent);
}

double sma_generator (sma_data_t *sma, double value) {
sma->sum += value;
sma->data[sma->lastpos%sma->size] = value;
sma->lastpos++;
unsigned int size=sma->size;
if(sma->lastpos >= sma->size) {
sma->sum -= sma->data[sma->lastpos%sma->size];
} else {
size=sma->lastpos;
}
return sma->sum/size;
}

int64_t get_time_millis() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000LL + (tv.tv_usec / 1000LL));
}
9 changes: 9 additions & 0 deletions components/oap-common/oap_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,12 @@ void heap_log_free(heap_log* log) {
ESP_LOGD("debug", "----------> leaked : %d", xPortGetFreeHeapSize() - initial_heap);
}
}

void hexdump(const unsigned char *data, int len) {
char str[80];
str[0]=0;
for(int i=0;i<len;i++){
sprintf(str, "%s %02x", str, data[i]);
}
ESP_LOGD("debug", "%s",str);
}
Loading