Skip to content

Commit

Permalink
feat: add Improv WiFi support
Browse files Browse the repository at this point in the history
  • Loading branch information
DriftKingTW committed May 21, 2023
1 parent b6575fe commit 00134ae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lib_deps =
tinypico/TinyPICO Helper Library@^1.4.0
bblanchon/ArduinoJson@^6.19.4
xreef/PCF8574 library@^2.3.4
jnthas/Improv WiFi Library@^0.0.1
build_flags = -D USE_NIMBLE
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
34 changes: 33 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ int contentIcon = 0;

// Set web server port number to 80
WebServer server(80);
ImprovWiFi improvSerial(&Serial);

void onImprovWiFiErrorCb(ImprovTypes::Error err) {
Serial.println("Error: " + String(err));
}

void onImprovWiFiConnectedCb(const char *ssid, const char *password) {
// Save ssid and password to config.json
DynamicJsonDocument doc(256);

doc["ssid"] = ssid;
doc["password"] = password;

File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
Serial.println("Failed to open config file for writing");
}
if (serializeJson(doc, configFile) == 0) {
Serial.println("Failed to write to config file");
}
configFile.close();
}

void setup() {
Serial.begin(BAUD_RATE);
Expand All @@ -135,6 +157,15 @@ void setup() {

printSpacer();

Serial.println("Starting improv serial work...");
improvSerial.setDeviceInfo(ImprovTypes::ChipFamily::CF_ESP32,
"Schnell Firmware", "0.3.0 beta",
"Schnell Keyboard");
improvSerial.onImprovError(onImprovWiFiErrorCb);
improvSerial.onImprovConnected(onImprovWiFiConnectedCb);

printSpacer();

pcf8574RotaryExtension.encoder(encoderPinA, encoderPinB);
pcf8574RotaryExtension.pinMode(encoderSW, INPUT_PULLUP);
pcf8574RotaryExtension.pinMode(extensionBtn1, INPUT_PULLUP);
Expand Down Expand Up @@ -432,7 +463,8 @@ void ledTask(void *pvParameters) {
void networkTask(void *pvParameters) {
while (true) {
server.handleClient();
vTaskDelay(100 / portTICK_PERIOD_MS);
improvSerial.handleSerial();
vTaskDelay(50 / portTICK_PERIOD_MS);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <BleKeyboard.h>
#include <EEPROM.h>
#include <ESPmDNS.h>
#include <ImprovWiFiLibrary.h>
#include <PCF8574.h>
#include <SPIFFS.h>
#include <TinyPICO.h>
Expand Down

0 comments on commit 00134ae

Please sign in to comment.