Skip to content

Commit

Permalink
v41.0 (#73)
Browse files Browse the repository at this point in the history
* API: MHZ-19B ABC and ZeroCalibration
  • Loading branch information
yakumo-saki authored Feb 15, 2021
1 parent e1706a8 commit 9cf1300
Show file tree
Hide file tree
Showing 24 changed files with 383 additions and 138 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"unordered_map": "cpp",
"vector": "cpp",
"initializer_list": "cpp",
"unordered_set": "cpp"
"unordered_set": "cpp",
"*.cpp___": "cpp"
}
}
94 changes: 57 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,45 @@ Maybe I can support ST7789 on ESP8266. but not in TODO.

EnvBoyX has http API.

| METHOD | ENDPOINT | RETURN | description |
| ------ | ------------- | -------------------------- |
| GET | / | JSON | sensor value as JSON.|
| GET | /ping | TEXT | returns pong. |
| GET | /stastics | JSON | stastics JSON |
| GET | /brightness?value=<brightness> | TEXT | set display brightness (0-255) 0 means OFF |
| GET | /display?value=<1 or 0> | TEXT | set display power (1 = ON / 0 = OFF) |
| POST | /goto_setup | TEXT | Go to setup mode at next boot |
| minVer | METHOD | ENDPOINT | RETURN | description |
| ------| ------ | ------------- | -------------------------- | -------|
| 2.0 | GET | / | JSON | sensor value as JSON.|
| 2.0 | GET | /ping | TEXT | returns pong. |
| 39.0 | GET | /stastics | JSON | stastics JSON |
| 3.4 | GET | /brightness?value=<brightness> | TEXT | set display brightness (0-255) 0 means OFF |
| 3.4 | GET | /display?value=<1 or 0> | TEXT | set display power (1 = ON / 0 = OFF) |
| 40.0 | POST | /goto_setup | TEXT | Go to setup mode at next boot |
| 41.0 | POST | /mhz19b/abc | TEXT | value=1 ON value=0 OFF |
| 41.0 | POST | /mhz19b/zeroCalibration | TEXT | __DANGER__ Use if you know what you are doing |

NOTE: There is no reboot API, because of security reason.

#### note
#### cURL examples

* brightness and display power function is NOT WORKING in ST7789 (v3.0)
These are example of calling API

## how to write
##### Simple get API

use esptools.py or PlatformIO IDE.
```
curl http://[envboy IP or mDNShostname.local]/
{"product":"EnvBoyX","uptime":"01:18:02","uptimeMills":4682994,"temparature":"28.60","humidity":"35.00","pressure":"976.81","luminous":"16","luminousIr":"2","co2ppm":"-999","co2ppmAccuracy":"","rssi":-12}
```

##### GET with parameter API

```
esptool.py write_flash 0x1000 filename.bin
curl http://[envboy IP or mDNShostname.local]/brightness?value=100`
OK
```

* Get binary from releases page.
##### POST without parameter API

```
$ curl -X POST http://[envboy IP or mDNShostname.local]/goto_setup
OK
```

# appendix

## Setups I am using

Expand All @@ -164,7 +179,7 @@ esptool.py write_flash 0x1000 filename.bin
* WeMos D1mini
* NodeMCU V3

## Version History
# Version History

* BUGFIX: Bug fix
* FIX: Fix not bug, but not friendly behavior
Expand All @@ -173,13 +188,18 @@ esptool.py write_flash 0x1000 filename.bin
* DROP: Delete some functions
* NOTE: other things

### v40.1
## v41.0: MH-Z19B update

* ADD: API: MH-Z19B Auto Baseline Calibration ON/OFF
* ADD: API: MH-Z19B Zero Calibration

## v40.1: Bugfix release for v40

* FIX: SSD1306: Missing unit when no alerts
* CHANGE: Add minor version
* CHANGE: Delete startup first screen

### v40
## v40: Pressure Delta update

* FIX: CO2 ppm alert value is not good.
* ADD: Add POST /goto_setup API.
Expand All @@ -193,14 +213,14 @@ esptool.py write_flash 0x1000 filename.bin
* ADD: Pressure delta
* CHANGE: ST7789: Normal: Dont show co2 when no co2 sensor.

### v39
## v39: SH1106 Support release

* CHANGE: CONFIG: Add SSD1306 / SH1106 switch
* CHANGE: HTTP: ESP32: Stop Async Web server. back to standard webserver to reduce code duplicate #42
* ADD: WiFi RSSI to JSON
* FIX: ST7789: T: header align

### v38
## v38: Small update release

* CHANGE: CONFIG: ESP32 now uses SPIFFS instead of LITTLEFS but no format or setup required (remove LITTLEFS to SPIFFS wrapper because of compile error)
* CHANGE: SSD1306: Move to U8G2 graphic library
Expand All @@ -209,96 +229,96 @@ esptool.py write_flash 0x1000 filename.bin
* CHANGE: ST7789: Draw wait for reconfigure bar using graphics
* BUGFIX: CONFIG: coution 2 High value is not saved. (due to insufficient buffer)

### v37
## v37: Alert update.

* VERSION: 37. next version is v38.
* BUGFIX: Alert settings are not saved on ESP32.
* BUGFIX: Alert settings are not propery saved.
* CHANGE: Switch to squix78 -> thingpulse (same library)
* CONFIG: Shorten JSON keys about alerts(reconfig required)

### v3.6
## v3.6: Bugfix release.

* LICENSE: EnvBoyX is now under APL 2.0 , Affected to all versions. (license terms are not shown before)
* NOTE: LICENSE: EnvBoyX is now under APL 2.0 , Affected to all versions. (license terms are not shown before)
* BUGFIX: TSL2561 can't enabled
* CHANGE: Serial speed changed to 74880. (was 115200)
* BUGFIX: ping API returns invalid JSON
* BUGFIX: Display glitch when bigmode and show lux

### v3.5
## v3.5

* CHANGE: Config: version 9 (was 8) and using JSON format
* ADD: Config: Migration between versions

### v3.4
## v3.4

* CHANGE: Config: version 8 (was 6)
* BUGFIX: SSD1306 not shown in Setup Mode
* ADD: Default Brightness setting
* ADD: Screen Flip setting

### v3.3
## v3.3

* BUGFIX: MH-Z19B wrong message
* BUGFIX: Wrong uptime on JSON
* ADD: ST7789 Brightness change (via Web API)
* ADD: Watchdog timer (ESP32 only)
* CHANGE: Use TimerCall

### v3.2
## v3.2

* FIX: Avoid using delay
* ADD: I2C scan on startup.
* BUGFIX: ESP8266: I2C not working
* DROP: ESP8266: ST7789 is not supported (because of Pin config)

### v3.1
## v3.1

* ADD: vertical display mode(bigger font. ST7789 only)
* FIX: Refactoring

### v3.0
## v3.0

* ADD: ST7789 Support (T-Display)
* NOTE: ST7789 is initial support, some screens are simplifyed.

### v2.7: Display item change update
## v2.7: Display item change update

* CHANGE: Delete alive indicator "*" after EnvBoyX string.
* ADD: alive indicator. EnvBoyX's "X" character now blinks.
* CHANGE: prefix "IP:" before IP address
* ADD: mDNS name display. IP/mDNS display switches 3 sec interval.
* NOTE: Abort TFT display implementation.

### v2.6
## v2.6

* BUGFIX: Fix mDNS not working

### v2.5
## v2.5

* ADD: /display endpoint.

### v2.4
## v2.4

* ADD: /brightness endpoint.

### v2.3
## v2.3

* FIX: Unifing EnvBoyX (ESP8266) and EnvBoyX32 (ESP32) again.

### v2.2
## v2.2

* missing version due to bug.

### v2.1
## v2.1

* FIX: Split EnvBoyX (8266) and EnvBoyX32 (ESP32)

### v2.0
## v2.0

* FIX: Move Arduino IDE to Platform.IO

### before v2.0
## before v2.0

* https://github.com/yakumo-saki/envboy
* https://github.com/yakumo-saki/EnvBoyMQTT
3 changes: 3 additions & 0 deletions cloc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cloc --exclude-dir=.pio,.vscode,_release,.github . --by-file-by-lang
4 changes: 3 additions & 1 deletion create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ cp ${MYDIR}/docs/how_to_write*.md ${RELEASE_DIR}

banner "Creating Archive"

rm -f ${MYDIR}/EnvBoyX*.tar.gz

# git ブランチからファイル名判定
branch=`git branch --contains | cut -b3-`
branch=`git symbolic-ref --short HEAD`

if [ $branch = "master" ]; then
RELEASE_FILE_PATH=${MYDIR}/EnvBoyX.tar.gz
Expand Down
13 changes: 0 additions & 13 deletions include/http_normal.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/*
* http_normal.cpp 非機種依存部分
*/
String http_normal_not_found_html();

String http_normal_data_json();

String http_normal_ping_json();

/*
* http_normal_board.cpp 機種依存部分
*/

/**
* 初期化
*/
Expand Down
10 changes: 10 additions & 0 deletions include/network/http_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#ifdef ESP32
#include <WebServer.h>
typedef WebServer HTTPWEBSERVER;
#endif

#ifdef ESP8266
#include <ESP8266WebServer.h>
typedef ESP8266WebServer HTTPWEBSERVER;
#endif
3 changes: 3 additions & 0 deletions include/network/http_api_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "network/http_api.h"

void http_api_base_setup();
7 changes: 7 additions & 0 deletions include/network/http_api_base_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <Arduino.h>

String http_normal_not_found_html();

String http_normal_data_json();

String http_normal_ping_json();
3 changes: 3 additions & 0 deletions include/network/http_api_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "network/http_api.h"

void http_api_config_setup();
3 changes: 3 additions & 0 deletions include/network/http_api_display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "network/http_api.h"

void http_api_display_setup();
3 changes: 3 additions & 0 deletions include/network/http_api_mhz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "network/http_api.h"

void http_api_mhz_setup();
3 changes: 3 additions & 0 deletions include/network/http_api_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <Arduino.h>

bool parseBooleanString(const String value);
18 changes: 18 additions & 0 deletions include/sensors/mhz19_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@
int mhz_read_data_uart();

void mhz_setup_uart();

/**
* Auto Baseline calibration を設定する
* @return 設定に成功したか否か
*/
bool mhz_set_abc(bool onoff);

/**
* Auto Baseline calibration の状態を取得
* @return ON or OFF
*/
bool mhz_get_abc();

/**
* Zero Calibration (現在のppmを400ppmとみなす)
* 外気で20分動作させたあとに実行する。
*/
bool mhz_do_zero_calibration();
4 changes: 2 additions & 2 deletions src/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
extern const String product_short = "EBX";
// EnvBoyX
extern const String product = "EnvBoyX";
extern const String ver = "40";
extern const String minorVer = "1";
extern const String ver = "41";
extern const String minorVer = "0";
extern const String ver_long = " Ver." + ver + "." + minorVer;

// EnvBoyX Ver.53.0
Expand Down
2 changes: 1 addition & 1 deletion src/main_normal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ void loop_normal() {
http_loop_normal();

// mainlog("Wait for Next tick.");

yield();
watchdog_feed();
}
46 changes: 46 additions & 0 deletions src/network/api/http_api_base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <Arduino.h>

#include "config.h"

#include "global.h"
#include "display/display.h"
#include "network/http_api.h"
#include "network/http_api_base_json.h"

extern HTTPWEBSERVER server;

void http_handle_data() {
String message = http_normal_data_json();
server.send(200, MIME_JSON, message);
}

void http_handle_ping() {
String message = http_normal_ping_json();
server.send(200, MIME_JSON, message);
}

void http_handle_stastics() {
server.send(200, MIME_JSON, stasticsJSON);
}

void http_handle_goto_setup() {

remove_configure_flag_file();

String message = "OK. Entering setup mode at next boot.";
server.send( 200, MIME_TEXT, message );
}

void http_handle_not_found() {
String message = http_normal_not_found_html();
server.send(404, MIME_HTML, message);
}

void http_api_base_setup() {
server.on ( "/ping", HTTP_GET, http_handle_ping);
server.on ( "/", HTTP_GET, http_handle_data );
server.on ( "/stastics", HTTP_GET, http_handle_stastics );
server.on ( "/goto_setup", HTTP_POST, http_handle_goto_setup );

server.onNotFound ( http_handle_not_found );
}
Loading

0 comments on commit 9cf1300

Please sign in to comment.