Skip to content

Commit

Permalink
fix CI and ESP8266
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis authored Mar 28, 2023
1 parent 7be47db commit 0479918
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
pip install platformio
- name: Cppcheck
run: |
pio check --flags "--suppress=unusedFunction" --skip-packages
pio check --fail-on-defect=low --flags "--enable=warning --enable=style --enable=performance --suppress=unusedFunction --suppress=preprocessorErrorDirective" --skip-packages
4 changes: 2 additions & 2 deletions examples/simple-esp32/simple-esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void loop() {
if (millis() - lastMillis > 10000) {
lastMillis = millis();
uint8_t signalQuality = espMqttManagerHelpers::signalQuality();
char sqStr[5];
snprintf(sqStr, sizeof(sqStr), "%d%", signalQuality);
char sqStr[4];
snprintf(sqStr, sizeof(sqStr), "%d", signalQuality);
espMqttManager::mqttClient.publish("test/topic", 0, false, sqStr);
}
espMqttManager::loop();
Expand Down
6 changes: 3 additions & 3 deletions examples/simple-esp8266/simple-esp8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

void setup() {
delay(10000);
Serial.begin(115200);
Serial.begin(74880);
espMqttManager::setup();
espMqttManager::start();
}
Expand All @@ -14,8 +14,8 @@ void loop() {
if (millis() - lastMillis > 10000) {
lastMillis = millis();
uint8_t signalQuality = espMqttManagerHelpers::signalQuality();
char sqStr[5];
snprintf(sqStr, sizeof(sqStr), "%d%", signalQuality);
char sqStr[4];
snprintf(sqStr, sizeof(sqStr), "%d", signalQuality);
espMqttManager::mqttClient.publish("test/topic", 0, false, sqStr);
}
espMqttManager::loop();
Expand Down
4 changes: 2 additions & 2 deletions examples/tls-esp32/tls-esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void loop() {
if (millis() - lastMillis > 10000) {
lastMillis = millis();
uint8_t signalQuality = espMqttManagerHelpers::signalQuality();
char sqStr[5];
snprintf(sqStr, sizeof(sqStr), "%d%", signalQuality);
char sqStr[4];
snprintf(sqStr, sizeof(sqStr), "%d", signalQuality);
espMqttManager::mqttClient.publish("test/topic", 0, false, sqStr);
}
espMqttManager::loop();
Expand Down
34 changes: 34 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[platformio]
default_envs = esp32

[env]
framework = arduino

[common]
build_flags=
-Wall
-Wextra
-Wshadow

[env:esp8266]
platform = espressif8266
board = d1_mini
build_flags =
${common.build_flags}
-D DEBUG_ESP_PORT=Serial
-DDEBUG_ESP_MQTT_MANAGER
monitor_filters = esp8266_exception_decoder
monitor_speed = 74880
build_type = debug

[env:esp32]
platform = espressif32
board = lolin_c3_mini
build_flags =
${common.build_flags}
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
-DDEBUG_ESP_MQTT_MANAGER
-D RGB_BUILTIN=SOC_GPIO_PIN_COUNT+7
monitor_filters = esp32_exception_decoder
monitor_speed = 115200
build_type = debug
1 change: 1 addition & 0 deletions scripts/CI/platformio_esp8266.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ build_flags =
-Wall
-Wextra
-Werror
board_build.filesystem = littlefs
4 changes: 3 additions & 1 deletion src/Blinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ Blinker::Blinker(int pin)

#ifdef RGB_BUILTIN
void Blinker::blink(uint32_t interval, Colour colour) {
_interval = interval;
#else
void Blinker::blink(uint32_t interval) {
#endif
#ifdef RGB_BUILTIN
_colour = colour;
#endif
_interval = interval;
_lastInterval = millis() - _interval;
_ledState = false;
_state = true;
Expand Down
6 changes: 3 additions & 3 deletions src/Blinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ the LICENSE file.

#pragma once

#ifndef !defined(ARDUINO_ARCH_ESP32) || !defined(ARDUINO_ARCH_ESP8266)
#if !defined(ARDUINO_ARCH_ESP32) && !defined(ARDUINO_ARCH_ESP8266)
#error Platform not supported
#endif

Expand All @@ -30,7 +30,7 @@ extern Colour orange;

class Blinker {
public:
Blinker(int pin);
explicit Blinker(int pin);
#ifdef RGB_BUILTIN
void blink(uint32_t interval, Colour colour);
#else
Expand All @@ -50,4 +50,4 @@ class Blinker {
#endif
};

} // end namespace espMqttManagerHelpers
} // end namespace espMqttManagerHelpers
4 changes: 2 additions & 2 deletions src/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ void handleUpdate(const uint8_t* payload, size_t length, size_t index, size_t to
if (Update.end()) {
espMqttManagerHelpers::updated = true;
} else {
//Update.printError(Serial);
// Update.printError(Serial);
Update.clearError();
}
}
}

} // end namespace espMqttManagerHelpers
} // end namespace espMqttManagerHelpers
2 changes: 1 addition & 1 deletion src/Uptime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ char* Uptime::getUptimeStr() {

Uptime uptime;

} // end namespace espMqttManagerHelpers
} // end namespace espMqttManagerHelpers
2 changes: 1 addition & 1 deletion src/Uptime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the LICENSE file.
#include <stddef.h> // size_t
#include <stdint.h> // uintx_t

#ifndef !defined(ARDUINO_ARCH_ESP32) || !defined(ARDUINO_ARCH_ESP8266)
#if !defined(ARDUINO_ARCH_ESP32) && !defined(ARDUINO_ARCH_ESP8266)
#error Platform not supported
#endif

Expand Down
31 changes: 25 additions & 6 deletions src/espMqttManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ the LICENSE file.
*/

#include <Arduino.h>

#if defined(ARDUINO_ARCH_ESP8266)
#include <LittleFS.h>
#define EMM_FILE_READ "r"
#elif defined(ARDUINO_ARCH_ESP32)
#include <SPIFFS.h>
#define EMM_FILE_READ FILE_READ
#endif

#include <IPAddress.h>

#include <ArduinoJson.h>
Expand Down Expand Up @@ -40,7 +48,11 @@ espMqttClientSecure espMqttManager::mqttClient;
#else
espMqttClient espMqttManager::mqttClient;
#endif
#ifdef RGB_BUILTIN
espMqttManagerHelpers::Blinker blinker(RGB_BUILTIN);
#else
espMqttManagerHelpers::Blinker blinker(LED_BUILTIN);
#endif

void idle();
void waitForWiFi();
Expand Down Expand Up @@ -73,12 +85,18 @@ struct Config {
} config;

bool getConfig() {
if (!SPIFFS.begin(true)){
emm_log_e("Error mounting SPIFFS");
#if defined(ARDUINO_ARCH_ESP8266)
#define EMM_FILESYSTEM LittleFS
#elif defined(ARDUINO_ARCH_ESP32)
#define EMM_FILESYSTEM SPIFFS
#endif

if (!EMM_FILESYSTEM.begin()) {
emm_log_e("Error mounting filesystem");
return false;
}
File file = SPIFFS.open(EMM_CONFIG_FILE);
if(!file){
File file = EMM_FILESYSTEM.open(EMM_CONFIG_FILE, EMM_FILE_READ);
if (!file) {
emm_log_e("Error opening settings.json");
return false;
}
Expand Down Expand Up @@ -108,7 +126,7 @@ bool getConfig() {
doc["devicename"] | "",
sizeof(config.devicename));
file.close();
SPIFFS.end();
EMM_FILESYSTEM.end();
return true;
}

Expand Down Expand Up @@ -158,7 +176,7 @@ void espMqttManager::start() {
void espMqttManager::loop() {
// espMqttManager doesn't use WiFi events so we have to monitor WiFi here
if (WiFi.status() != WL_CONNECTED) {
//mqttClient.disconnect(true); // this will set state back to _mqttConnecting
// mqttClient.disconnect(true); // this will set state back to _mqttConnecting
state = waitForWiFi;
}
blinker.loop();
Expand Down Expand Up @@ -295,6 +313,7 @@ void onMqttClientConnected(bool sessionPresent) {
}

void onMqttClientDisconnected(espMqttClientTypes::DisconnectReason reason) {
(void) reason;
timer = millis();
if (state > idle && state <= connected) {
#ifdef RGB_BUILTIN
Expand Down

0 comments on commit 0479918

Please sign in to comment.