Skip to content

Commit

Permalink
Add insecure API package (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
MallocArray authored Sep 5, 2024
1 parent 0b1c2fb commit 594d6cf
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ESPHome yaml files for AirGradient devices to maintain the research and accuracy

* Remove substitution line such as `config_version: 2.0.5` from the main file, as this has been moved into the board package file
* Updated to 4.0.0 versions, skipping 3.x to avoid confusion with current AirGradient official firmware
* 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

## Changes

Expand Down
6 changes: 6 additions & 0 deletions packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Uploads sensor data to the [AirGradient Dashboard](https://app.airgradient.com/d

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

# airgradient_api_d1_mini_insecure.yaml

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.

This file is for devices based on the D1 Mini chip (AG Basic and AG Pro) with all current sensors, including SGP41

## airgradient_api_esp32-c3_dual_pms5003t.yaml

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
Expand Down
61 changes: 61 additions & 0 deletions packages/airgradient_api_d1_mini_insecure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
interval:
- interval: 2.5min
# Send data to AirGradient API server
then:
if:
condition:
switch.is_on: upload_airgradient
then:
- http_request.post:
# http://api.airgradient.com/public/docs/api/v1/
# AirGradient URL with the last 6 of MAC address all lower case
url: !lambda |-
return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures";
headers:
Content-Type: application/json
json:
wifi: !lambda return to_string(id(wifi_dbm).state);
rco2: !lambda return to_string(id(co2).state);
pm01: !lambda return to_string(id(pm_1_0).state);
pm02: !lambda return to_string(id(pm_2_5).state);
pm10: !lambda return to_string(id(pm_10_0).state);
pm003Count: !lambda return to_string(id(pm_0_3um).state);
atmp: !lambda return to_string(id(temp_raw).state);
atmpCompensated: !lambda return to_string(id(temp).state);
rhum: !lambda return to_string(id(humidity_raw).state);
rhumCompensated: !lambda return to_string(id(humidity).state);
tvocIndex: !lambda return to_string(id(voc).state);
noxIndex: !lambda return to_string(id(nox).state);
# Uptime in minutes as the boot value
boot: !lambda return to_string(round(id(device_uptime).state/60));

switch:
- platform: template
name: "Upload to AirGradient Dashboard"
id: upload_airgradient
restore_mode: RESTORE_DEFAULT_OFF
optimistic: True

esphome:
on_boot:
priority: 200 # Network connections setup
then:
if:
condition:
switch.is_on: upload_airgradient
then:
- http_request.post:
# Return wifi signal -50 as soon as device boots to show activity on AirGradient Dashboard site
# Using -50 instead of actual value as the wifi_signal sensor has not reported a value at this point in boot process
url: !lambda |-
return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures";
headers:
Content-Type: application/json
json:
wifi: !lambda return to_string(-50);

http_request:
timeout: 1s # Setting short to try to prevent watchdog reboots http://github.com/esphome/issues/issues/2853
# Used to support POST request to send data to AirGradient
# http://esphome.io/components/http_request.html
verify_ssl: false # Must be explicityly set to false when using Arduino framework
2 changes: 1 addition & 1 deletion packages/airgradient_d1_mini_board.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
substitutions:
config_version: 4.0.4
config_version: 4.0.5

esphome:
name: "${name}"
Expand Down
2 changes: 1 addition & 1 deletion packages/airgradient_esp32-c3_board.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
substitutions:
config_version: 4.0.3
config_version: 4.0.5

esphome:
name: "${name}"
Expand Down

0 comments on commit 594d6cf

Please sign in to comment.