-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
901 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.pio | ||
*.log | ||
*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// ESP32 Secure Base Basic Example | ||
// Copyright (c) 2019 Thorsten von Eicken, all rights reserved | ||
|
||
// Example application that prints Wifi info in loop(). | ||
// When starting up, it will block in setup() until WiFi has connected to an access point. | ||
// If a configuration has been set-up, it tries to connect to the configured AP for a few seconds. | ||
// If that fails, it starts an AP and waits for a configuration to be set. | ||
// While in set-up mode, it resets every few minutes in case that fixes something. | ||
|
||
#include <Arduino.h> | ||
#include <WiFi.h> | ||
#include <ESPSecureBase.h> | ||
|
||
//===== I/O pins/devices | ||
|
||
#define BUTTON 0 | ||
#ifndef LED | ||
#define LED 1 | ||
#endif | ||
|
||
// configuration portal timing | ||
|
||
#define CONF_CONN_TIMEOUT 10 // seconds to try to connect to AP before setting up config portal | ||
#define CONF_PORTAL_TIMEOUT (5*60) // seconds before config portal stops and device resets | ||
|
||
// MQTT message handling | ||
|
||
void onMqttMessage(char* topic, char* payload, MqttProps properties, | ||
size_t len, size_t index, size_t total) | ||
{ | ||
if (strcmp(topic, "system/offset") == 0) { | ||
//onTimeZone(topic, payload, properties, len, index, total); | ||
} else if (strlen(topic) == mqTopicLen+4 && len == total && | ||
strncmp(topic, mqTopic, mqTopicLen) == 0 && | ||
strcmp(topic+mqTopicLen, "/ota") == 0) | ||
{ | ||
ESBOTA::begin(payload, len); | ||
} | ||
} | ||
|
||
//===== Setup | ||
|
||
void setup() { | ||
ESBConfig config; | ||
|
||
Serial.begin(115200); | ||
printf("\n===== ESP32 Secure Base Example =====\n"); | ||
pinMode(BUTTON, INPUT_PULLUP); | ||
|
||
#if 0 | ||
// wipe-out saved wifi settings for testing purposes | ||
WiFi.begin("none", "no-no-no"); | ||
delay(1000); | ||
#endif | ||
|
||
// Configure Wifi. | ||
bool connected = config.setup(CONF_CONN_TIMEOUT, CONF_PORTAL_TIMEOUT); | ||
|
||
// If config failed, reset device to start over. | ||
if (!connected) { | ||
printf("*** Resetting...\n"); | ||
delay(500); // time for the portal to send responses | ||
ESP.restart(); | ||
while (true) delay(100); | ||
} | ||
|
||
printf("Wifi connected to %s\n", WiFi.SSID().c_str()); | ||
|
||
mqttSetup(config); | ||
|
||
printf("\n===== Setup complete\n"); | ||
} | ||
|
||
void reconfig() { | ||
ESBConfig config; | ||
bool saved = config.reconfig(CONF_CONN_TIMEOUT, CONF_PORTAL_TIMEOUT); | ||
if (saved) { | ||
mqttSetup(config); | ||
} | ||
} | ||
|
||
void loop() { | ||
//WiFi.printDiag(Serial); | ||
printf("* Wifi:%s MQTT:%s\n", WiFi.isConnected()?"OK":"---", mqttClient.connected()?"OK":"---"); | ||
mqttLoop(); | ||
|
||
if (digitalRead(BUTTON) == LOW) reconfig(); | ||
|
||
delay(2000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[platformio] | ||
default_envs = usb | ||
src_dir = . | ||
|
||
[common] | ||
build_flags = -DASYNC_TCP_SSL_ENABLED | ||
lib_deps = | ||
https://github.com/tve/AsyncTCP.git#mbed-tls-try2 | ||
https://github.com/me-no-dev/ESPAsyncWebServer.git | ||
https://github.com/tve/ESPAsyncWiFiManager.git | ||
https://github.com/tve/async-mqtt-client.git | ||
lib_ignore = ESPAsyncTCP | ||
|
||
[env:usb] | ||
#platform = https://github.com/platformio/platform-espressif32.git#feature/stage | ||
platform = espressif32 | ||
framework = arduino | ||
board = nodemcu-32s | ||
build_flags = ${common.build_flags} | ||
# -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG | ||
lib_deps = ${common.lib_deps} | ||
lib_ignore = ${common.lib_ignore} | ||
lib_ldf_mode = chain+ | ||
upload_port = /dev/ttyUSB0 | ||
monitor_port = /dev/ttyUSB0 | ||
monitor_speed = 115200 | ||
|
||
[env:ota] | ||
platform = espressif32 | ||
framework = arduino | ||
board = nodemcu-32s | ||
mqtt_device = esp32-c09b7ca4ae30 | ||
build_flags = ${common.build_flags} | ||
lib_deps = ${common.lib_deps} | ||
lib_ldf_mode = chain+ | ||
upload_protocol = custom | ||
extra_scripts = pre:../../publish_firmware.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name":"ESPSecureBase", | ||
"description":"Secure MQTT Base Project Libray for ESP32", | ||
"keywords":"", | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/tve/esp32-secure-base.git" | ||
}, | ||
"version": "0.1.0", | ||
"frameworks": "arduino", | ||
"platforms": "espressif32", | ||
"build": { | ||
"libCompatMode": "strict" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// The following are not used, but if they're not included here then platformio doesn't | ||
// find them when they're included in some other library. Sigh... | ||
|
||
#include <FS.h> | ||
#include <SPIFFS.h> | ||
#include <DNSServer.h> | ||
#include <ArduinoJson.h> |
Oops, something went wrong.