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

WIP: make the code compile for esp32 #1039

Draft
wants to merge 15 commits into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
15 changes: 15 additions & 0 deletions .github/workflows/airohr-firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ jobs:
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Load cached ~/.platformio
uses: actions/cache@v2
with:
path: ~/.platformio
key: platformio-${{ hashFiles('**/platformio.ini') }}
restore-keys: platformio-

- name: Load cached ./.pio
uses: actions/cache@v2
with:
path: ./.pio
key: pio-${{ hashFiles('**/platformio.ini') }}
restore-keys: pio-

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
Expand Down
8 changes: 8 additions & 0 deletions airrohr-firmware/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@

Please refer to [Contributing README](./Contributing.md) for details.

## ESP32 support

The support is still experimental. Run the following to complile the code for the [ES32 WROOM board](https://docs.platformio.org/en/latest/boards/espressif32/denky32.html):

```
pio run --environment esp32
```

## WiFi configuration
For German Version see: [Konfiguration der Sensoren](https://github.com/opendata-stuttgart/meta/wiki/Konfiguration-der-Sensoren)

Expand Down
13 changes: 11 additions & 2 deletions airrohr-firmware/airrohr-firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include <pgmspace.h>

// increment on change
#define SOFTWARE_VERSION_STR "NRZ-2024-136-B1"
#define SOFTWARE_VERSION_STR "NRZ-2024-135"
macbre marked this conversation as resolved.
Show resolved Hide resolved
String SOFTWARE_VERSION(SOFTWARE_VERSION_STR);

/*****************************************************************
Expand Down Expand Up @@ -87,7 +87,11 @@ String SOFTWARE_VERSION(SOFTWARE_VERSION_STR);
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <HardwareSerial.h>
#include <hwcrypto/sha.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL (4, 4, 0)
#include <sha/sha_parallel_engine.h>
#else
#include <hwcrypto/sha.h>
#endif
#include <WebServer.h>
#include <ESPmDNS.h>
#endif
Expand Down Expand Up @@ -2917,7 +2921,9 @@ static void waitForWifiToConnect(int maxRetries)
* WiFi auto connecting script *
*****************************************************************/

#if defined(ESP8266)
static WiFiEventHandler disconnectEventHandler;
#endif

static void connectWifi()
{
Expand Down Expand Up @@ -5391,7 +5397,10 @@ static void init_display()
// modifying the I2C speed to 400k, which overwhelms some of the
// sensors.
Wire.setClock(100000);

#if defined(ESP8266)
Wire.setClockStretchLimit(150000);
#endif
}

/*****************************************************************
Expand Down
2 changes: 2 additions & 0 deletions airrohr-firmware/defines.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <bearssl/bearssl_ssl.h>

#if defined(ESP8266)
#define SENSOR_BASENAME "esp8266-"
#define OTA_BASENAME "/airrohr"
Expand Down
21 changes: 19 additions & 2 deletions airrohr-firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ board_build.f_cpu = 160000000L
; (like OneWire, LiquidCrystal_I2C and TinyGPSPlus)

lib_deps_external =
paulstoffregen/[email protected].5
paulstoffregen/[email protected].8
marcoschwartz/[email protected]
adafruit/Adafruit BMP085 [email protected]
adafruit/Adafruit HTU21DF [email protected]
Expand All @@ -55,6 +55,8 @@ lib_deps_external =
bblanchon/[email protected]
ThingPulse/ESP8266 and ESP32 OLED driver for SSD1306 displays @ ^4.3.0
mikalhart/[email protected]
[email protected] ; https://registry.platformio.org/libraries/arduino-libraries/ArduinoBearSSL
arduino-libraries/ArduinoECCX08@^1.3.8

; system libraries from platform -> no version number
lib_deps_esp8266_platform =
Expand Down Expand Up @@ -89,7 +91,7 @@ extra_scripts = platformio_script.py
# needs to be adjusted to the matching version from
# https://github.com/platformio/platform-espressif8266/releases
platform_version = [email protected]
platform_version_esp32 = espressif32@1.11.1 ; using Arduino core 1.0.4
platform_version_esp32 = espressif32@6.9.0

[env]
build_unflags = -Os
Expand Down Expand Up @@ -468,3 +470,18 @@ board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags} -DINTL_UA
lib_deps = ${common.lib_deps_esp8266}
extra_scripts = ${common.extra_scripts}

[env:esp32]
lang = en
platform = ${common.platform_version_esp32}
framework = arduino
board = upesy_wroom ; https://docs.platformio.org/en/latest/boards/espressif32/upesy_wroom.html
board_build.ldscript = ${common.board_build.ldscript}
board_build.filesystem = ${common.board_build.filesystem}
build_flags = ${common.build_flags_esp32_release} '-DINTL_EN' '-DESP32_WROOM_MODULE'
lib_deps = ${common.lib_deps_esp32}
extra_scripts = ${common.extra_scripts}
; change microcontroller
board_build.mcu = esp32
; change MCU frequency
board_build.f_cpu = 240000000
8 changes: 7 additions & 1 deletion airrohr-firmware/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ bool launchUpdateLoader(const String& md5) {
*****************************************************************/
String check_display_value(double value, double undef, uint8_t len, uint8_t str_len) {
RESERVE_STRING(s, 15);
s = (value != undef ? String(value, len) : String("-"));

#if defined(ESP8266)
s = (value != undef ? String(value, len) : String("-"));
#endif
#if defined(ESP32)
s = (value != undef ? String(value, (unsigned int) len) : String("-"));
#endif
while (s.length() < str_len) {
s = " " + s;
}
Expand Down
7 changes: 6 additions & 1 deletion airrohr-firmware/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <HardwareSerial.h>
#include <hwcrypto/sha.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL (4, 4, 0)
#include <sha/sha_parallel_engine.h>
#else
#include <hwcrypto/sha.h>
#endif
#include <freertos/queue.h>
#endif

Expand Down Expand Up @@ -95,6 +99,7 @@ extern SoftwareSerial serialIPS;
#define serialIPS (Serial1)
#endif


enum class PmSensorCmd {
Start,
Stop,
Expand Down