Skip to content

Commit 594d6cf

Browse files
authored
Add insecure API package (#86)
1 parent 0b1c2fb commit 594d6cf

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ESPHome yaml files for AirGradient devices to maintain the research and accuracy
66

77
* Remove substitution line such as `config_version: 2.0.5` from the main file, as this has been moved into the board package file
88
* Updated to 4.0.0 versions, skipping 3.x to avoid confusion with current AirGradient official firmware
9+
* Now defaulting to https for AirGradient API communication. If older devices (DIY and Pro models) go into constant reboots, switch to the api package `airgradient_api_d1_mini_insecure.yaml` to revert to the original communication method
910

1011
## Changes
1112

packages.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/d
1010

1111
Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/dashboard). This file is for devices based on the D1 Mini chip (AG Basic and AG Pro) with all current sensors, including SGP41
1212

13+
# airgradient_api_d1_mini_insecure.yaml
14+
15+
Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/dashboard) using http instead of https. Some boards, such as the ESP8266 D1 Mini can sometimes go into a reboot loop when communicating over https. Original firmware used http without issue, so offering this as an alternative for devices that require it.
16+
17+
This file is for devices based on the D1 Mini chip (AG Basic and AG Pro) with all current sensors, including SGP41
18+
1319
## airgradient_api_esp32-c3_dual_pms5003t.yaml
1420

1521
Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/dashboard). This file is for devices based on the ESP32-C3 chip (AG ONE and OpenAir) with dual PMS5003t sensors. Designed for the Outdoor OpenAir model O-PPT1
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
interval:
2+
- interval: 2.5min
3+
# Send data to AirGradient API server
4+
then:
5+
if:
6+
condition:
7+
switch.is_on: upload_airgradient
8+
then:
9+
- http_request.post:
10+
# http://api.airgradient.com/public/docs/api/v1/
11+
# AirGradient URL with the last 6 of MAC address all lower case
12+
url: !lambda |-
13+
return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures";
14+
headers:
15+
Content-Type: application/json
16+
json:
17+
wifi: !lambda return to_string(id(wifi_dbm).state);
18+
rco2: !lambda return to_string(id(co2).state);
19+
pm01: !lambda return to_string(id(pm_1_0).state);
20+
pm02: !lambda return to_string(id(pm_2_5).state);
21+
pm10: !lambda return to_string(id(pm_10_0).state);
22+
pm003Count: !lambda return to_string(id(pm_0_3um).state);
23+
atmp: !lambda return to_string(id(temp_raw).state);
24+
atmpCompensated: !lambda return to_string(id(temp).state);
25+
rhum: !lambda return to_string(id(humidity_raw).state);
26+
rhumCompensated: !lambda return to_string(id(humidity).state);
27+
tvocIndex: !lambda return to_string(id(voc).state);
28+
noxIndex: !lambda return to_string(id(nox).state);
29+
# Uptime in minutes as the boot value
30+
boot: !lambda return to_string(round(id(device_uptime).state/60));
31+
32+
switch:
33+
- platform: template
34+
name: "Upload to AirGradient Dashboard"
35+
id: upload_airgradient
36+
restore_mode: RESTORE_DEFAULT_OFF
37+
optimistic: True
38+
39+
esphome:
40+
on_boot:
41+
priority: 200 # Network connections setup
42+
then:
43+
if:
44+
condition:
45+
switch.is_on: upload_airgradient
46+
then:
47+
- http_request.post:
48+
# Return wifi signal -50 as soon as device boots to show activity on AirGradient Dashboard site
49+
# Using -50 instead of actual value as the wifi_signal sensor has not reported a value at this point in boot process
50+
url: !lambda |-
51+
return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures";
52+
headers:
53+
Content-Type: application/json
54+
json:
55+
wifi: !lambda return to_string(-50);
56+
57+
http_request:
58+
timeout: 1s # Setting short to try to prevent watchdog reboots http://github.com/esphome/issues/issues/2853
59+
# Used to support POST request to send data to AirGradient
60+
# http://esphome.io/components/http_request.html
61+
verify_ssl: false # Must be explicityly set to false when using Arduino framework

packages/airgradient_d1_mini_board.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
substitutions:
2-
config_version: 4.0.4
2+
config_version: 4.0.5
33

44
esphome:
55
name: "${name}"

packages/airgradient_esp32-c3_board.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
substitutions:
2-
config_version: 4.0.3
2+
config_version: 4.0.5
33

44
esphome:
55
name: "${name}"

0 commit comments

Comments
 (0)