init commit
commit
a94611af06
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"board": "esp32:esp32:esp32",
|
||||||
|
"configuration": "PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=none",
|
||||||
|
"port": "COM4",
|
||||||
|
"sketch": "Valnet.ino",
|
||||||
|
"programmer": "AVR ISP"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Win32",
|
||||||
|
"includePath": [
|
||||||
|
"C:\\Users\\Marcus\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\**",
|
||||||
|
"C:\\Users\\Marcus\\Documents\\Arduino\\libraries\\**",
|
||||||
|
"C:\\Program Files (x86)\\Arduino\\libraries\\**",
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"C:\\Users\\Marcus\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\**"
|
||||||
|
],
|
||||||
|
"defines": [
|
||||||
|
"_DEBUG",
|
||||||
|
"UNICODE",
|
||||||
|
"_UNICODE",
|
||||||
|
"USBCON"
|
||||||
|
],
|
||||||
|
"windowsSdkVersion": "10.0.17134.0",
|
||||||
|
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "c++17",
|
||||||
|
"intelliSenseMode": "msvc-x64",
|
||||||
|
"forcedInclude": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"array": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"condition_variable": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"map": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"mutex": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"queue": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"ratio": "cpp",
|
||||||
|
"shared_mutex": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"thread": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"unordered_set": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"xfacet": "cpp",
|
||||||
|
"xhash": "cpp",
|
||||||
|
"xiosbase": "cpp",
|
||||||
|
"xlocale": "cpp",
|
||||||
|
"xlocbuf": "cpp",
|
||||||
|
"xlocinfo": "cpp",
|
||||||
|
"xlocmes": "cpp",
|
||||||
|
"xlocmon": "cpp",
|
||||||
|
"xlocnum": "cpp",
|
||||||
|
"xloctime": "cpp",
|
||||||
|
"xmemory": "cpp",
|
||||||
|
"xmemory0": "cpp",
|
||||||
|
"xstddef": "cpp",
|
||||||
|
"xstring": "cpp",
|
||||||
|
"xtr1common": "cpp",
|
||||||
|
"xtree": "cpp",
|
||||||
|
"xutility": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"cinttypes": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 394 KiB |
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef IDENTITY_H
|
||||||
|
#define IDENTITY_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
#ifndef MEMORY_H
|
||||||
|
#define MEMORY_H
|
||||||
|
|
||||||
|
#include "EEPROM.h"
|
||||||
|
// #include "Arduino.h"
|
||||||
|
#include "hardwareSerial.h"
|
||||||
|
|
||||||
|
struct DataChunk {
|
||||||
|
const int offset;
|
||||||
|
const int width;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MemoryClass {
|
||||||
|
public:
|
||||||
|
void begin(const int size);
|
||||||
|
void dump();
|
||||||
|
const byte readByte(const int address);
|
||||||
|
void readString(struct DataChunk chunk, char* dest);
|
||||||
|
void writeString(struct DataChunk chunk, const char* string);
|
||||||
|
void clearAll();
|
||||||
|
private:
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
|
void MemoryClass::begin(const int size) {
|
||||||
|
this->size = size;
|
||||||
|
if (!EEPROM.begin( size )) {
|
||||||
|
Serial.println("failed to initialise EEPROM!");
|
||||||
|
} else {
|
||||||
|
Serial.printf("EEPROM Size: %d\n", size);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryClass::dump() {
|
||||||
|
int i = 0;
|
||||||
|
while(i < this->size) {
|
||||||
|
if(i != 0 && i % 32 == 0) Serial.println("");
|
||||||
|
char c = (char)EEPROM.read(i);
|
||||||
|
if(c < 0x20 || c == 127 || c == 255) {
|
||||||
|
Serial.print('.');
|
||||||
|
} else {
|
||||||
|
Serial.print(c);
|
||||||
|
}
|
||||||
|
i ++;
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
}
|
||||||
|
|
||||||
|
const byte MemoryClass::readByte(const int address) {
|
||||||
|
return EEPROM.read(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryClass::readString(struct DataChunk chunk, char* dest) {
|
||||||
|
char data[32];
|
||||||
|
int idx = 0;
|
||||||
|
while(idx < chunk.width) {
|
||||||
|
data[idx] = (char)EEPROM.read(chunk.offset + idx);
|
||||||
|
idx ++;
|
||||||
|
}
|
||||||
|
strcpy(dest, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryClass::writeString(struct DataChunk chunk, const char* string) {
|
||||||
|
if(strlen(string) > chunk.width - 1) {
|
||||||
|
return; // TODO make this error out!
|
||||||
|
}
|
||||||
|
|
||||||
|
int cell = chunk.offset;
|
||||||
|
for(int i = 0; i < strlen(string); i ++) {
|
||||||
|
EEPROM.write(cell, string[i]);
|
||||||
|
cell ++;
|
||||||
|
}
|
||||||
|
EEPROM.write(cell, 0);
|
||||||
|
EEPROM.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryClass::clearAll() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryClass Memory;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
#ifndef RGBLED_H
|
||||||
|
#define RGBLED_H
|
||||||
|
|
||||||
|
struct RGBLED {
|
||||||
|
int pinR;
|
||||||
|
int pinG;
|
||||||
|
int pinB;
|
||||||
|
int channelR;
|
||||||
|
int channelG;
|
||||||
|
int channelB;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RGBLED STATUS_LED = { 0, 2, 15, 0, 1, 2 };
|
||||||
|
|
||||||
|
struct LEDColor {
|
||||||
|
int r;
|
||||||
|
int g;
|
||||||
|
int b;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LEDColor RED = { 255, 0, 0 };
|
||||||
|
struct LEDColor GREEN = { 0, 255, 0 };
|
||||||
|
struct LEDColor BLUE = { 0, 0, 255 };
|
||||||
|
struct LEDColor CYAN = { 0, 50, 255 };
|
||||||
|
struct LEDColor MAGENTA = { 255, 0, 255 };
|
||||||
|
struct LEDColor YELLOW = { 255, 255, 0 };
|
||||||
|
|
||||||
|
struct LEDColor BLACK = { 0, 0, 0 };
|
||||||
|
struct LEDColor WHITE = { 255, 255, 255 };
|
||||||
|
|
||||||
|
void initRGBLED(struct RGBLED led) {
|
||||||
|
ledcSetup(led.channelR, 5000, 8);
|
||||||
|
ledcAttachPin(led.pinR, led.channelR);
|
||||||
|
ledcSetup(led.channelG, 5000, 8);
|
||||||
|
ledcAttachPin(led.pinG, led.channelG);
|
||||||
|
ledcSetup(led.channelB, 5000, 8);
|
||||||
|
ledcAttachPin(led.pinB, led.channelB);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRGBLEDColor(struct RGBLED led, struct LEDColor color) {
|
||||||
|
ledcWrite(led.pinR, color.r);
|
||||||
|
ledcWrite(led.pinG, color.g);
|
||||||
|
ledcWrite(led.pinB, color.b);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
#ifndef SETTINGS_H
|
||||||
|
#define SETTINGS_H
|
||||||
|
|
||||||
|
#include "Memory.h"
|
||||||
|
#include "StrUtil.h"
|
||||||
|
|
||||||
|
#define EEPROM_SIZE 512
|
||||||
|
|
||||||
|
#define SSID_WIDTH 32
|
||||||
|
#define PASSWD_WIDTH 32
|
||||||
|
#define RSA_KEY_WIDTH 64
|
||||||
|
#define FLAGS_WIDTH 16
|
||||||
|
|
||||||
|
struct WiFiNetworkSettings {
|
||||||
|
char ssid[SSID_WIDTH];
|
||||||
|
char passwd[PASSWD_WIDTH];
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct WiFiNetworkSettings NULL_WIFI_SETTINGS = {"", ""};
|
||||||
|
|
||||||
|
bool operator==(const WiFiNetworkSettings& lhs, const WiFiNetworkSettings& rhs)
|
||||||
|
{
|
||||||
|
return lhs.ssid == rhs.ssid && lhs.passwd == rhs.passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const struct DataChunk SSID_CHUNK = {0x000, SSID_WIDTH};
|
||||||
|
const struct DataChunk PASSWD_CHUNK = {0x020, PASSWD_WIDTH};
|
||||||
|
const struct DataChunk PUBLIC_KEY_CHUNK = {0x040, RSA_KEY_WIDTH};
|
||||||
|
const struct DataChunk PRIVATE_KEY_CHUNK = {0x080, RSA_KEY_WIDTH};
|
||||||
|
const struct DataChunk FLAGS_CHUNK = {0x0C0, FLAGS_WIDTH}; //ends at 0x0D0
|
||||||
|
// EEPROM ENDS AT 0x200
|
||||||
|
|
||||||
|
class SettingsClass {
|
||||||
|
public:
|
||||||
|
void begin();
|
||||||
|
void writeWifi(const char* ssid, const char* passwd);
|
||||||
|
void clearWifi();
|
||||||
|
struct WiFiNetworkSettings readWifi();
|
||||||
|
};
|
||||||
|
|
||||||
|
void SettingsClass::begin() {
|
||||||
|
Memory.begin(EEPROM_SIZE);
|
||||||
|
|
||||||
|
if(Memory.readByte(0) == 255) {
|
||||||
|
Memory.clearAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsClass::writeWifi(const char* ssid, const char* passwd) {
|
||||||
|
Memory.writeString(SSID_CHUNK, ssid);
|
||||||
|
Memory.writeString(PASSWD_CHUNK, passwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsClass::clearWifi() {
|
||||||
|
Memory.writeString(SSID_CHUNK, "");
|
||||||
|
Memory.writeString(PASSWD_CHUNK, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WiFiNetworkSettings SettingsClass::readWifi() {
|
||||||
|
if(Memory.readByte(SSID_CHUNK.offset) == 0) return NULL_WIFI_SETTINGS;
|
||||||
|
|
||||||
|
|
||||||
|
// char ssid = *(Memory.readString(SSID_CHUNK));
|
||||||
|
// char passwd = *(Memory.readString(PASSWD_CHUNK));
|
||||||
|
|
||||||
|
WiFiNetworkSettings net;
|
||||||
|
|
||||||
|
char ssid[SSID_WIDTH];
|
||||||
|
char passwd[PASSWD_WIDTH];
|
||||||
|
Memory.readString(SSID_CHUNK, ssid);
|
||||||
|
Memory.readString(PASSWD_CHUNK, passwd);
|
||||||
|
strcpy(net.ssid, ssid);
|
||||||
|
strcpy(net.passwd, passwd);
|
||||||
|
|
||||||
|
return net;
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsClass Settings;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef STRUTIL_H
|
||||||
|
#define STRUTIL_H
|
||||||
|
|
||||||
|
#include "WString.h"
|
||||||
|
|
||||||
|
class StrUtilClass {
|
||||||
|
public:
|
||||||
|
char* str2cptr(String str);
|
||||||
|
const char* str2ccptr(String str);
|
||||||
|
};
|
||||||
|
|
||||||
|
char* StrUtilClass::str2cptr(String str) {
|
||||||
|
char* output;
|
||||||
|
str.toCharArray(output, str.length());
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* StrUtilClass::str2ccptr(String str) {
|
||||||
|
return str.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
StrUtilClass StrUtil();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
#include "WiFi.h"
|
||||||
|
#include "EEPROM.h"
|
||||||
|
#include "mdns.h"
|
||||||
|
|
||||||
|
#include "RGBLED.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println(" ===== [ VALNET ] =====");
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
Settings.begin();
|
||||||
|
|
||||||
|
initRGBLED(STATUS_LED);
|
||||||
|
setRGBLEDColor(STATUS_LED, RED);
|
||||||
|
|
||||||
|
if(Settings.readWifi() == NULL_WIFI_SETTINGS) {
|
||||||
|
enterSetupMode();
|
||||||
|
} else {
|
||||||
|
startValnet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
setRGBLEDColor(STATUS_LED, RED);
|
||||||
|
delay(500);
|
||||||
|
setRGBLEDColor(STATUS_LED, BLACK);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
setRGBLEDColor(STATUS_LED, GREEN);
|
||||||
|
delay(500);
|
||||||
|
setRGBLEDColor(STATUS_LED, BLACK);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
setRGBLEDColor(STATUS_LED, BLUE);
|
||||||
|
delay(500);
|
||||||
|
setRGBLEDColor(STATUS_LED, BLACK);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
// setRGBLEDColor(STATUS_LED, CYAN);
|
||||||
|
// delay(500);
|
||||||
|
// setRGBLEDColor(STATUS_LED, BLACK);
|
||||||
|
// delay(500);
|
||||||
|
|
||||||
|
// setRGBLEDColor(STATUS_LED, MAGENTA);
|
||||||
|
// delay(500);
|
||||||
|
// setRGBLEDColor(STATUS_LED, BLACK);
|
||||||
|
// delay(500);
|
||||||
|
|
||||||
|
// setRGBLEDColor(STATUS_LED, YELLOW);
|
||||||
|
// delay(500);
|
||||||
|
// setRGBLEDColor(STATUS_LED, BLACK);
|
||||||
|
// delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterSetupMode() {
|
||||||
|
// AHHHHHHHHHHH SHIT
|
||||||
|
}
|
||||||
|
|
||||||
|
void startValnet() {
|
||||||
|
WiFiNetworkSettings network = Settings.readWifi();
|
||||||
|
|
||||||
|
Serial.println("SSID: " + String(network.ssid));
|
||||||
|
Serial.println("PASS: " + String(network.passwd));
|
||||||
|
|
||||||
|
WiFi.begin(network.ssid, network.passwd);
|
||||||
|
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
Serial.println("Connecting to WiFi..");
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
Serial.println("wifi connected!");
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue