first commit
This commit is contained in:
commit
ad999db44c
10
.gitignore
vendored
Executable file
10
.gitignore
vendored
Executable file
@ -0,0 +1,10 @@
|
||||
.pio
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
website-source
|
||||
website-source-copy
|
||||
website-zipped
|
||||
website-zipped-bak
|
67
.travis.yml
Executable file
67
.travis.yml
Executable file
@ -0,0 +1,67 @@
|
||||
# Continuous Integration (CI) is the practice, in software
|
||||
# engineering, of merging all developer working copies with a shared mainline
|
||||
# several times a day < https://docs.platformio.org/page/ci/index.html >
|
||||
#
|
||||
# Documentation:
|
||||
#
|
||||
# * Travis CI Embedded Builds with PlatformIO
|
||||
# < https://docs.travis-ci.com/user/integration/platformio/ >
|
||||
#
|
||||
# * PlatformIO integration with Travis CI
|
||||
# < https://docs.platformio.org/page/ci/travis.html >
|
||||
#
|
||||
# * User Guide for `platformio ci` command
|
||||
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
|
||||
#
|
||||
#
|
||||
# Please choose one of the following templates (proposed below) and uncomment
|
||||
# it (remove "# " before each line) or use own configuration according to the
|
||||
# Travis CI documentation (see above).
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# Template #1: General project. Test it using existing `platformio.ini`.
|
||||
#
|
||||
|
||||
# language: python
|
||||
# python:
|
||||
# - "2.7"
|
||||
#
|
||||
# sudo: false
|
||||
# cache:
|
||||
# directories:
|
||||
# - "~/.platformio"
|
||||
#
|
||||
# install:
|
||||
# - pip install -U platformio
|
||||
# - platformio update
|
||||
#
|
||||
# script:
|
||||
# - platformio run
|
||||
|
||||
|
||||
#
|
||||
# Template #2: The project is intended to be used as a library with examples.
|
||||
#
|
||||
|
||||
# language: python
|
||||
# python:
|
||||
# - "2.7"
|
||||
#
|
||||
# sudo: false
|
||||
# cache:
|
||||
# directories:
|
||||
# - "~/.platformio"
|
||||
#
|
||||
# env:
|
||||
# - PLATFORMIO_CI_SRC=path/to/test/file.c
|
||||
# - PLATFORMIO_CI_SRC=examples/file.ino
|
||||
# - PLATFORMIO_CI_SRC=path/to/test/directory
|
||||
#
|
||||
# install:
|
||||
# - pip install -U platformio
|
||||
# - platformio update
|
||||
#
|
||||
# script:
|
||||
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
|
7
.vscode/extensions.json
vendored
Executable file
7
.vscode/extensions.json
vendored
Executable file
@ -0,0 +1,7 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
6
.vscode/settings.json
vendored
Executable file
6
.vscode/settings.json
vendored
Executable file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"terminal.integrated.env.linux": {
|
||||
"PATH": "/home/rohan/.platformio/penv/bin:/home/rohan/.platformio/penv:/home/rohan/.cargo/bin:/home/rohan/bin:/home/rohan/.local/bin:/home/rohan/.nvm/versions/node/v12.10.0/bin:/home/rohan/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/rohan/.cargo/bin",
|
||||
"PLATFORMIO_CALLER": "vscode"
|
||||
}
|
||||
}
|
BIN
data/NotoSansBold15.vlw
Executable file
BIN
data/NotoSansBold15.vlw
Executable file
Binary file not shown.
BIN
data/NotoSansBold36.vlw
Executable file
BIN
data/NotoSansBold36.vlw
Executable file
Binary file not shown.
BIN
data/Nunito-Light20.vlw
Executable file
BIN
data/Nunito-Light20.vlw
Executable file
Binary file not shown.
BIN
data/Nunito-Light28.vlw
Executable file
BIN
data/Nunito-Light28.vlw
Executable file
Binary file not shown.
BIN
data/Nunito-Light32.vlw
Executable file
BIN
data/Nunito-Light32.vlw
Executable file
Binary file not shown.
BIN
data/Nunito-Regular20.vlw
Executable file
BIN
data/Nunito-Regular20.vlw
Executable file
Binary file not shown.
BIN
data/WebSocket.js.gz
Executable file
BIN
data/WebSocket.js.gz
Executable file
Binary file not shown.
BIN
data/colors.css.gz
Normal file
BIN
data/colors.css.gz
Normal file
Binary file not shown.
27
data/combinedSettingsFile.txt
Executable file
27
data/combinedSettingsFile.txt
Executable file
@ -0,0 +1,27 @@
|
||||
|
||||
{
|
||||
"settings": [
|
||||
{
|
||||
"shour": 14,
|
||||
"fadePeriod": 60,
|
||||
"smin": 0,
|
||||
"ehour": 16,
|
||||
"emin": 0
|
||||
},
|
||||
{
|
||||
"shour": 15,
|
||||
"fadePeriod": 60,
|
||||
"smin": 49,
|
||||
"ehour": 20,
|
||||
"emin": 0
|
||||
},
|
||||
{
|
||||
"shour": 15,
|
||||
"fadePeriod": 60,
|
||||
"smin": 0,
|
||||
"ehour": 20,
|
||||
"emin": 0
|
||||
}
|
||||
],
|
||||
"manual": "False"
|
||||
}
|
BIN
data/edit.html.gz
Executable file
BIN
data/edit.html.gz
Executable file
Binary file not shown.
BIN
data/favicon.ico.gz
Executable file
BIN
data/favicon.ico.gz
Executable file
Binary file not shown.
BIN
data/index.html.gz
Executable file
BIN
data/index.html.gz
Executable file
Binary file not shown.
BIN
data/ledcontrol.html.gz
Executable file
BIN
data/ledcontrol.html.gz
Executable file
Binary file not shown.
BIN
data/loadMenu.js.gz
Normal file
BIN
data/loadMenu.js.gz
Normal file
Binary file not shown.
BIN
data/main.css.gz
Normal file
BIN
data/main.css.gz
Normal file
Binary file not shown.
BIN
data/main.js.gz
Normal file
BIN
data/main.js.gz
Normal file
Binary file not shown.
BIN
data/manifest.json.gz
Executable file
BIN
data/manifest.json.gz
Executable file
Binary file not shown.
BIN
data/manualMode-ajax.html.gz
Executable file
BIN
data/manualMode-ajax.html.gz
Executable file
Binary file not shown.
BIN
data/manualMode.html.gz
Executable file
BIN
data/manualMode.html.gz
Executable file
Binary file not shown.
BIN
data/menu.html.gz
Executable file
BIN
data/menu.html.gz
Executable file
Binary file not shown.
BIN
data/nunito-regular-webfont.woff
Executable file
BIN
data/nunito-regular-webfont.woff
Executable file
Binary file not shown.
BIN
data/nunito-regular-webfont.woff2
Executable file
BIN
data/nunito-regular-webfont.woff2
Executable file
Binary file not shown.
BIN
data/settings-ajax.html.gz
Executable file
BIN
data/settings-ajax.html.gz
Executable file
Binary file not shown.
BIN
data/settings-success.html.gz
Executable file
BIN
data/settings-success.html.gz
Executable file
Binary file not shown.
BIN
data/settings.html.gz
Executable file
BIN
data/settings.html.gz
Executable file
Binary file not shown.
BIN
data/settings.js.gz
Normal file
BIN
data/settings.js.gz
Normal file
Binary file not shown.
7
data/settingsFile1.txt
Executable file
7
data/settingsFile1.txt
Executable file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"shour1": 16,
|
||||
"fadePeriod1": 30,
|
||||
"smin1": 0,
|
||||
"ehour": 22,
|
||||
"emin": 0
|
||||
}
|
7
data/settingsFile2.txt
Executable file
7
data/settingsFile2.txt
Executable file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"shour2": 16,
|
||||
"fadePeriod2": 30,
|
||||
"smin2": 0,
|
||||
"ehour": 22,
|
||||
"emin": 0
|
||||
}
|
7
data/settingsFile3.txt
Executable file
7
data/settingsFile3.txt
Executable file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"shour3": 16,
|
||||
"fadePeriod3": 30,
|
||||
"smin3": 0,
|
||||
"ehour": 22,
|
||||
"emin": 0
|
||||
}
|
BIN
data/success.html.gz
Executable file
BIN
data/success.html.gz
Executable file
Binary file not shown.
BIN
data/temperatures.txt.gz
Normal file
BIN
data/temperatures.txt.gz
Normal file
Binary file not shown.
10
include.js
Executable file
10
include.js
Executable file
@ -0,0 +1,10 @@
|
||||
$(function(){
|
||||
var includes = $('[data-include]');
|
||||
jQuery.each(includes, function(){
|
||||
var file = '/' + $(this).data('include') + '.html';
|
||||
$(this).load(file);
|
||||
});
|
||||
});
|
||||
// $(document).ready(function(){
|
||||
// $( "#header" ).load( "/menu.html" );
|
||||
// });
|
39
include/README
Executable file
39
include/README
Executable file
@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
lib/README
Executable file
46
lib/README
Executable file
@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
24
platformio.ini
Executable file
24
platformio.ini
Executable file
@ -0,0 +1,24 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:nodemcuv2]
|
||||
; CXXFLAGS = -W -Wall -Wextra -Werror -std=c++11
|
||||
platform = espressif8266
|
||||
; lib_extra_dirs = ~/Documents/Arduino/libraries
|
||||
board = nodemcuv2
|
||||
framework = arduino
|
||||
upload_speed = 460800
|
||||
; build_flags = -D BEARSSL_SSL_BASIC
|
||||
; baud_rate = 115200
|
||||
monitor_speed = 115200
|
||||
board_build.f_cpu = 160000000L
|
||||
; lib_deps =
|
||||
; MAX31850 DallasTemp
|
||||
|
943
src/sketch_oct17esp.cpp
Executable file
943
src/sketch_oct17esp.cpp
Executable file
@ -0,0 +1,943 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <FS.h>
|
||||
#include <WebSocketsServer.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include <Streaming.h>
|
||||
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
|
||||
#include <SPI.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
// #define AA_FONT_SMALL "NotoSansBold15"
|
||||
#define AA_FONT_SMALL "Nunito-Light28"
|
||||
|
||||
#define AA_FONT_LARGE "NotoSansBold36"
|
||||
|
||||
#define ONE_WIRE_BUS D1
|
||||
|
||||
#include <sketch_oct17esp.hpp>
|
||||
|
||||
SoftwareSerial s(D3, D2); //RX.TX
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
#define COORDSIZE 12
|
||||
|
||||
static char temperaturesJson[200];
|
||||
|
||||
const char *guiStrings[] PROGMEM = {"Humi: ", "Time: ",
|
||||
"PH: ", "Temp: ",
|
||||
"Temp: ", "Temp: ",
|
||||
"Temp: ", "Temp: ",
|
||||
"Temp: ", "Temp: ",
|
||||
"Temp: ", "Temp: "};
|
||||
|
||||
class Coordinates
|
||||
{
|
||||
public:
|
||||
int x[COORDSIZE];
|
||||
int y[COORDSIZE];
|
||||
Coordinates()
|
||||
{
|
||||
int count = 5;
|
||||
Serial.println("Init coords");
|
||||
|
||||
Serial << "count = " << count << endl;
|
||||
for (int i = 0; i < COORDSIZE; i++)
|
||||
{
|
||||
x[i] = 0;
|
||||
y[i] = count;
|
||||
if (i % 2 == 1)
|
||||
count = count + 37;
|
||||
// y[i] = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Coordinates coordinates; //object creation
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
const int SENSOR_RESOLUTION = 12;
|
||||
unsigned long lastTempRequest = 0;
|
||||
const unsigned int delayInMillisSensors = 750 / (1 << (12 - SENSOR_RESOLUTION));
|
||||
;
|
||||
|
||||
ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
|
||||
|
||||
ESP8266WebServer server(300); // create a web server on port 80
|
||||
WebSocketsServer webSocket(301); // create a websocket server on port 81
|
||||
|
||||
File fsUploadFile; // a File variable to temporarily store the received file
|
||||
|
||||
const char *ssid = "ESP8266 Access Point"; // The name of the Wi-Fi network that will be created
|
||||
const char *password = "thereisnospoon"; // The password required to connect to it, leave blank for an open network
|
||||
|
||||
const char *OTAName = "ESP8266"; // A name and a password for the OTA service
|
||||
const char *OTAPassword = "esp8266";
|
||||
const size_t bufferSize = JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(2) + 3 * JSON_OBJECT_SIZE(5);
|
||||
const size_t lcd_data_size = JSON_ARRAY_SIZE(8) + JSON_OBJECT_SIZE(1) + 30;
|
||||
|
||||
// #define LED_RED 15 // specify the pins with an RGB LED connected
|
||||
// #define LED_GREEN 12
|
||||
// #define LED_BLUE 13
|
||||
#define ARDUINO_TO_ESP_PIN D0
|
||||
// #define ESP_TO_ARDUINO_PIN D2
|
||||
|
||||
byte currentArduinoState;
|
||||
byte previousArduinoState;
|
||||
|
||||
const char *mdnsName = "esp8266"; // Domain name for the mDNS responder
|
||||
|
||||
/*__________________________________________________________SETUP__________________________________________________________*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
// pinMode(LED_RED, OUTPUT); // the pins with LEDs connected are outputs
|
||||
// pinMode(LED_GREEN, OUTPUT);
|
||||
// pinMode(LED_BLUE, OUTPUT);
|
||||
pinMode(ARDUINO_TO_ESP_PIN, INPUT);
|
||||
// pinMode(ESP_TO_ARDUINO_PIN, OUTPUT);
|
||||
// digitalWrite(ESP_TO_ARDUINO_PIN, 1);
|
||||
|
||||
Serial.begin(115200);
|
||||
s.begin(9600); // Start the Serial communication to send messages to the computer
|
||||
delay(10);
|
||||
Serial.println("\r\n");
|
||||
|
||||
startWiFi(); // Start a Wi-Fi access point, and try to connect to some given access points. Then wait for either an AP or STA connection
|
||||
|
||||
startOTA(); // Start the OTA service
|
||||
|
||||
startSPIFFS(); // Start the SPIFFS and list all contents
|
||||
|
||||
startWebSocket(); // Start a WebSocket server
|
||||
|
||||
startMDNS(); // Start the mDNS responder
|
||||
|
||||
startServer(); // Start a HTTP server with a file read handler and an upload handler
|
||||
|
||||
//displaySettings2();
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
bool font_missing = false;
|
||||
if (SPIFFS.exists("/NotoSansBold15.vlw") == false)
|
||||
font_missing = true;
|
||||
if (SPIFFS.exists("/NotoSansBold36.vlw") == false)
|
||||
font_missing = true;
|
||||
|
||||
if (font_missing)
|
||||
{
|
||||
Serial.println("\r\nFont missing in SPIFFS, did you upload it?");
|
||||
while (1)
|
||||
yield();
|
||||
}
|
||||
else
|
||||
Serial.println("\r\nFonts found OK.");
|
||||
|
||||
tft.setTextSize(2);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
|
||||
// for (int i = 0; i < COORDSIZE; i++)
|
||||
// {
|
||||
// Serial << FPSTR(guiStrings[i]);
|
||||
// }
|
||||
tft.loadFont(AA_FONT_SMALL);
|
||||
// tft.setTextFont(2);
|
||||
Serial.println();
|
||||
for (int i = 0; i < COORDSIZE; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
// tft.drawString("Temp: ", 165, coordinates.y[i], 2);
|
||||
tft.drawString(guiStrings[i], 5, coordinates.y[i]);
|
||||
coordinates.x[i] = 5 + tft.textWidth(guiStrings[i]) + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
tft.drawString(guiStrings[i], 165, coordinates.y[i]);
|
||||
coordinates.x[i] = 165 + tft.textWidth(guiStrings[i]) + 2;
|
||||
}
|
||||
}
|
||||
|
||||
// tft.drawString("afef",0,0);
|
||||
tft.unloadFont();
|
||||
// tft.setTextFont(2);
|
||||
|
||||
// Serial << "Printing x coordinates" << endl;
|
||||
// for (int i = 0; i < COORDSIZE; i++)
|
||||
// {
|
||||
// Serial << coordinates.x[i] << " ";
|
||||
// }
|
||||
|
||||
// Serial.println();
|
||||
|
||||
// Serial << "Printing x and y coordinates" << endl;
|
||||
// for (int i = 0; i < COORDSIZE; i++)
|
||||
// {
|
||||
// Serial << F("(") << coordinates.x[i] << F(",") << coordinates.y[i] << F(")")
|
||||
// << F(" ");
|
||||
// }
|
||||
Serial.println();
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
sensors.begin();
|
||||
sensors.setWaitForConversion(false);
|
||||
sensors.requestTemperatures();
|
||||
// delayInMillisSensors = 750 / (1 << (12 - SENSOR_RESOLUTION));
|
||||
// delayInMillisSensors = 1000;
|
||||
lastTempRequest = millis();
|
||||
}
|
||||
|
||||
/*__________________________________________________________LOOP__________________________________________________________*/
|
||||
|
||||
bool rainbow = false; // The rainbow effect is turned off on startup
|
||||
//bool arduinoON = false;
|
||||
unsigned long prevMillis = millis();
|
||||
int hue = 0;
|
||||
|
||||
void loop()
|
||||
{
|
||||
// // digitalWrite(ESP_TO_ARDUINO_PIN, 0);
|
||||
|
||||
webSocket.loop(); // constantly check for websocket events
|
||||
server.handleClient(); // run the server
|
||||
ArduinoOTA.handle(); // listen for OTA events
|
||||
previousArduinoState = currentArduinoState;
|
||||
currentArduinoState = digitalRead(ARDUINO_TO_ESP_PIN);
|
||||
if (previousArduinoState == LOW && currentArduinoState == HIGH)
|
||||
{
|
||||
Serial.println("Arduino turned on");
|
||||
//arduinoON = true;
|
||||
//combineSettings();
|
||||
displayCombinedSettings();
|
||||
Serial.println("Settings sent to arduino");
|
||||
}
|
||||
|
||||
if (rainbow)
|
||||
{ // if the rainbow effect is turned on
|
||||
if (millis() > prevMillis + 32)
|
||||
{
|
||||
if (++hue == 360) // Cycle through the color wheel (increment by one degree every 32 ms)
|
||||
hue = 0;
|
||||
setHue(hue); // Set the RGB LED to the right color
|
||||
prevMillis = millis();
|
||||
}
|
||||
}
|
||||
|
||||
// s.flush()
|
||||
if (s.available() > 0)
|
||||
{
|
||||
Serial << F("Received JSON from arduino") << endl;
|
||||
StaticJsonBuffer<100> jsonBuffer;
|
||||
// DynamicJsonBuffer jsonBuffer(100);
|
||||
JsonObject &root = jsonBuffer.parseObject(s);
|
||||
JsonArray &lcd_data = root["lcdData"];
|
||||
// lcd_data[0];
|
||||
char a[10];
|
||||
sprintf(a, lcd_data[1]);
|
||||
tft.drawString(a, coordinates.x[1], coordinates.y[1], 2);
|
||||
// int d = lcd_data[0];
|
||||
sprintf(a, lcd_data[0]);
|
||||
tft.drawString(a, coordinates.x[0], coordinates.y[0], 2);
|
||||
// tft.drawString("25.5C", coordinates.x[3], coordinates.y[3], 2);
|
||||
|
||||
root.printTo(Serial);
|
||||
// Serial << s.available() << endl;
|
||||
// s.flush();
|
||||
// Serial << (char)s.read() << endl;
|
||||
// sensors.requestTemperatures();
|
||||
// char str_temp[6];
|
||||
// dtostrf(sensors.getTempCByIndex(0), 1, 1, str_temp);
|
||||
// sprintf(a, "%s", str_temp);
|
||||
// tft.drawString(str_temp, coordinates.x[3], coordinates.y[3], 2);
|
||||
// Serial.println(sensors.getTempCByIndex(0));
|
||||
delay(50);
|
||||
}
|
||||
// sensors.requestTemperatures();
|
||||
// Serial.println(sensors.getTempCByIndex(0));
|
||||
// delay(1000);
|
||||
|
||||
// Serial << F("Serial available = ") << s.available() << endl;
|
||||
// delay(50);
|
||||
|
||||
// if (sensors.isConversionAvailable(0))
|
||||
// {
|
||||
// // tft.drawString("25.5C", coordinates.x[3], coordinates.y[3], 2);
|
||||
// Serial << "Reading avaialable" << endl;
|
||||
// char b[10];
|
||||
// char str_temp[6];
|
||||
// dtostrf(sensors.getTempCByIndex(0), 1, 1, str_temp);
|
||||
// sprintf(b, "%s", str_temp);
|
||||
// tft.drawString(str_temp, coordinates.x[3], coordinates.y[3], 2);
|
||||
// Serial.println(sensors.getTempCByIndex(0));
|
||||
// sensors.requestTemperatures();
|
||||
// }
|
||||
if (millis() - lastTempRequest >= delayInMillisSensors)
|
||||
{
|
||||
char b[10];
|
||||
char str_temp[6];
|
||||
// saveTemperatureJson();
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
JsonObject &root = jsonBuffer.createObject();
|
||||
if (root == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error");
|
||||
}
|
||||
JsonArray &temperatures = root.createNestedArray("temperatures");
|
||||
temperatures.add(sensors.getTempCByIndex(0));
|
||||
root.prettyPrintTo(Serial);
|
||||
root.prettyPrintTo(temperaturesJson);
|
||||
dtostrf(sensors.getTempCByIndex(0), 1, 1, str_temp);
|
||||
sprintf(b, "%s", str_temp);
|
||||
tft.drawString(str_temp, coordinates.x[3], coordinates.y[3], 2);
|
||||
// Serial.println(sensors.getTempCByIndex(0));
|
||||
// Serial << "Delay: " << delayInMillisSensors << endl;
|
||||
sensors.requestTemperatures();
|
||||
// delayInMillisSensors = 750 / (1 << (12 - SENSOR_RESOLUTION));
|
||||
lastTempRequest = millis();
|
||||
}
|
||||
}
|
||||
|
||||
/*__________________________________________________________SETUP_FUNCTIONS__________________________________________________________*/
|
||||
|
||||
void startWiFi()
|
||||
{ // Start a Wi-Fi access point, and try to connect to some given access points. Then wait for either an AP or STA connection
|
||||
WiFi.softAP(ssid, password); // Start the access point
|
||||
Serial.print("Access Point \"");
|
||||
Serial.print(ssid);
|
||||
Serial.println("\" started\r\n");
|
||||
|
||||
wifiMulti.addAP("Rohan-2", "coldpark735"); // add Wi-Fi networks you want to connect to
|
||||
wifiMulti.addAP("rohan", "Mir@1932");
|
||||
wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");
|
||||
|
||||
Serial.print(F("MAC: "));
|
||||
Serial.println(WiFi.macAddress());
|
||||
|
||||
Serial.println("Connecting");
|
||||
while (wifiMulti.run() != WL_CONNECTED && WiFi.softAPgetStationNum() < 1)
|
||||
{ // Wait for the Wi-Fi to connect
|
||||
delay(250);
|
||||
Serial.print('.');
|
||||
}
|
||||
Serial.println("\r\n");
|
||||
if (WiFi.softAPgetStationNum() == 0)
|
||||
{ // If the ESP is connected to an AP
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(WiFi.SSID()); // Tell us what network we're connected to
|
||||
Serial.print("IP address:\t");
|
||||
Serial.print(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
|
||||
}
|
||||
else
|
||||
{ // If a station is connected to the ESP SoftAP
|
||||
Serial.print("Station connected to ESP8266 AP");
|
||||
}
|
||||
Serial.println("\r\n");
|
||||
}
|
||||
|
||||
void startOTA()
|
||||
{ // Start the OTA service
|
||||
ArduinoOTA.setHostname(OTAName);
|
||||
ArduinoOTA.setPassword(OTAPassword);
|
||||
|
||||
ArduinoOTA.onStart([]() {
|
||||
Serial.println("Start");
|
||||
// digitalWrite(LED_RED, 0); // turn off the LEDs
|
||||
// digitalWrite(LED_GREEN, 0);
|
||||
// digitalWrite(LED_BLUE, 0);
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
Serial.println("\r\nEnd");
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR)
|
||||
Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR)
|
||||
Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR)
|
||||
Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR)
|
||||
Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR)
|
||||
Serial.println("End Failed");
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
Serial.println("OTA ready\r\n");
|
||||
}
|
||||
|
||||
void startSPIFFS()
|
||||
{ // Start the SPIFFS and list all contents
|
||||
SPIFFS.begin(); // Start the SPI Flash File System (SPIFFS)
|
||||
Serial.println("SPIFFS started. Contents:");
|
||||
{
|
||||
Dir dir = SPIFFS.openDir("/");
|
||||
while (dir.next())
|
||||
{ // List the file system contents
|
||||
String fileName = dir.fileName();
|
||||
size_t fileSize = dir.fileSize();
|
||||
Serial.printf("\tFS File: %s, size: %s\r\n", fileName.c_str(), formatBytes(fileSize).c_str());
|
||||
}
|
||||
Serial.printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void startWebSocket()
|
||||
{ // Start a WebSocket server
|
||||
webSocket.begin(); // start the websocket server
|
||||
webSocket.onEvent(webSocketEvent); // if there's an incomming websocket message, go to function 'webSocketEvent'
|
||||
Serial.println("WebSocket server started.");
|
||||
}
|
||||
|
||||
void startMDNS()
|
||||
{ // Start the mDNS responder
|
||||
MDNS.begin(mdnsName); // start the multicast domain name server
|
||||
Serial.print("mDNS responder started: http://");
|
||||
Serial.print(mdnsName);
|
||||
Serial.println(".local");
|
||||
}
|
||||
|
||||
void startServer()
|
||||
{ // Start a HTTP server with a file read handler and an upload handler
|
||||
server.on("/edit.html", HTTP_POST, []() { // If a POST request is sent to the /edit.html address,
|
||||
server.send(200, "text/plain", "");
|
||||
},
|
||||
handleFileUpload); // go to 'handleFileUpload'
|
||||
|
||||
server.onNotFound(handleNotFound); // if someone requests any other file or page, go to function 'handleNotFound'
|
||||
// and check if the file exists
|
||||
server.on("/settings.html", HTTP_POST, handleSettings);
|
||||
|
||||
server.on("/manualMode.html", HTTP_POST, handleManual);
|
||||
|
||||
server.on("/api/get/temperatures", HTTP_GET, []() {
|
||||
server.send(200, "application/json", temperaturesJson);
|
||||
});
|
||||
|
||||
server.begin(); // start the HTTP server
|
||||
Serial.println("HTTP server started.");
|
||||
}
|
||||
|
||||
/*__________________________________________________________SERVER_HANDLERS__________________________________________________________*/
|
||||
|
||||
void handleNotFound()
|
||||
{ // if the requested file or page doesn't exist, return a 404 not found error
|
||||
if (!handleFileRead(server.uri()))
|
||||
{ // check if the file exists in the flash memory (SPIFFS), if so, send it
|
||||
server.send(404, "text/plain", "404: File Not Found");
|
||||
}
|
||||
}
|
||||
|
||||
bool handleFileRead(String path)
|
||||
{ // send the right file to the client (if it exists)
|
||||
Serial.println("handleFileRead: " + path);
|
||||
if (path.endsWith("/"))
|
||||
path += "index.html"; // If a folder is requested, send the index file
|
||||
String contentType = getContentType(path); // Get the MIME type
|
||||
String pathWithGz = path + ".gz";
|
||||
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path))
|
||||
{ // If the file exists, either as a compressed archive, or normal
|
||||
if (SPIFFS.exists(pathWithGz)) // If there's a compressed version available
|
||||
path += ".gz"; // Use the compressed verion
|
||||
File file = SPIFFS.open(path, "r"); // Open the file
|
||||
size_t sent = server.streamFile(file, contentType); // Send it to the client
|
||||
file.close(); // Close the file again
|
||||
Serial.println(String("\tSent file: ") + path);
|
||||
return true;
|
||||
}
|
||||
Serial.println(String("\tFile Not Found: ") + path); // If the file doesn't exist, return false
|
||||
return false;
|
||||
}
|
||||
|
||||
void saveTemperatureJson()
|
||||
{
|
||||
StaticJsonBuffer<200> jsonBuffer;
|
||||
JsonObject &root = jsonBuffer.createObject();
|
||||
if (root == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error");
|
||||
}
|
||||
|
||||
// JsonArray &data = root.createNestedArray("data");
|
||||
// data.add(48);
|
||||
// data.add(2);
|
||||
JsonArray &temperatures = root.createNestedArray("temperatures");
|
||||
temperatures.add(sensors.getTempCByIndex(0));
|
||||
root.prettyPrintTo(Serial);
|
||||
root.prettyPrintTo(temperaturesJson);
|
||||
// if (SPIFFS.exists("/temperatures.txt"))
|
||||
// {
|
||||
// SPIFFS.remove("/temperatures.txt");
|
||||
// Serial.println("Old settings file removed");
|
||||
// }
|
||||
// File settingsFile = SPIFFS.open("/temperatures.txt", "w");
|
||||
// if (!settingsFile)
|
||||
// Serial.println("Error wriing json to file");
|
||||
// root.prettyPrintTo(settingsFile); //Export and save JSON object to SPIFFS area
|
||||
// Serial.println("Json written to file");
|
||||
// settingsFile.close();
|
||||
}
|
||||
void saveSettings1()
|
||||
{
|
||||
int shour = server.arg("shour").toInt();
|
||||
int smin = server.arg("smin").toInt();
|
||||
int fadePeriod = server.arg("fadePeriod").toInt();
|
||||
int ehour = server.arg("ehour").toInt();
|
||||
int emin = server.arg("emin").toInt();
|
||||
StaticJsonBuffer<200> jsonBuffer1;
|
||||
JsonObject &root = jsonBuffer1.createObject();
|
||||
if (root == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error");
|
||||
}
|
||||
root["shour1"] = shour;
|
||||
root["fadePeriod1"] = fadePeriod;
|
||||
root["smin1"] = smin;
|
||||
root["ehour"] = ehour;
|
||||
root["emin"] = emin;
|
||||
root.prettyPrintTo(Serial);
|
||||
if (SPIFFS.exists("/settingsFile1.txt"))
|
||||
{
|
||||
SPIFFS.remove("/settingsFile1.txt");
|
||||
Serial.println("Old settings file removed");
|
||||
}
|
||||
File settingsFile = SPIFFS.open("/settingsFile1.txt", "w");
|
||||
if (!settingsFile)
|
||||
Serial.println("Error wriing json to file");
|
||||
root.prettyPrintTo(settingsFile); //Export and save JSON object to SPIFFS area
|
||||
Serial.println("Json written to file");
|
||||
settingsFile.close();
|
||||
}
|
||||
void saveSettings2()
|
||||
{
|
||||
int shour = server.arg("shour").toInt();
|
||||
int smin = server.arg("smin").toInt();
|
||||
int fadePeriod = server.arg("fadePeriod").toInt();
|
||||
int ehour = server.arg("ehour").toInt();
|
||||
int emin = server.arg("emin").toInt();
|
||||
StaticJsonBuffer<200> jsonBuffer7;
|
||||
JsonObject &root = jsonBuffer7.createObject();
|
||||
if (root == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error");
|
||||
}
|
||||
root["shour2"] = shour;
|
||||
root["fadePeriod2"] = fadePeriod;
|
||||
root["smin2"] = smin;
|
||||
root["ehour"] = ehour;
|
||||
root["emin"] = emin;
|
||||
root.prettyPrintTo(Serial);
|
||||
if (SPIFFS.exists("/settingsFile2.txt"))
|
||||
{
|
||||
SPIFFS.remove("/settingsFile2.txt");
|
||||
Serial.println("Old settings file removed");
|
||||
}
|
||||
File settingsFile = SPIFFS.open("/settingsFile2.txt", "w");
|
||||
if (!settingsFile)
|
||||
Serial.println("Error writing json to file");
|
||||
root.prettyPrintTo(settingsFile); //Export and save JSON object to SPIFFS area
|
||||
Serial.println("Json written to file");
|
||||
settingsFile.close();
|
||||
}
|
||||
void saveSettings3()
|
||||
{
|
||||
int shour = server.arg("shour").toInt();
|
||||
int smin = server.arg("smin").toInt();
|
||||
int fadePeriod = server.arg("fadePeriod").toInt();
|
||||
int ehour = server.arg("ehour").toInt();
|
||||
int emin = server.arg("emin").toInt();
|
||||
StaticJsonBuffer<200> jsonBuffer8;
|
||||
JsonObject &root = jsonBuffer8.createObject();
|
||||
if (root == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error");
|
||||
}
|
||||
root["shour3"] = shour;
|
||||
root["fadePeriod3"] = fadePeriod;
|
||||
root["smin3"] = smin;
|
||||
root["ehour"] = ehour;
|
||||
root["emin"] = emin;
|
||||
root.prettyPrintTo(Serial);
|
||||
if (SPIFFS.exists("/settingsFile3.txt"))
|
||||
{
|
||||
SPIFFS.remove("/settingsFile3.txt");
|
||||
Serial.println("Old settings file removed");
|
||||
}
|
||||
File settingsFile = SPIFFS.open("/settingsFile3.txt", "w");
|
||||
if (!settingsFile)
|
||||
Serial.println("Error writing json to file");
|
||||
root.prettyPrintTo(Serial);
|
||||
root.prettyPrintTo(settingsFile); //Export and save JSON object to SPIFFS area
|
||||
Serial.println("Json written to file");
|
||||
settingsFile.close();
|
||||
}
|
||||
void combineSettings()
|
||||
{
|
||||
File file1 = SPIFFS.open("/settingsFile1.txt", "r");
|
||||
File file2 = SPIFFS.open("/settingsFile2.txt", "r");
|
||||
File file3 = SPIFFS.open("/settingsFile3.txt", "r");
|
||||
File file5 = SPIFFS.open("/manualMode.txt", "r");
|
||||
// Serial.println("2");
|
||||
if (SPIFFS.exists("/combinedSettingsFile.txt"))
|
||||
{
|
||||
SPIFFS.remove("/combinedSettingsFile.txt");
|
||||
}
|
||||
|
||||
File file4 = SPIFFS.open("/combinedSettingsFile.txt", "w");
|
||||
size_t size1 = file1.size(), size2 = file2.size(), size3 = file3.size(), size5 = file5.size();
|
||||
;
|
||||
std::unique_ptr<char[]> buf1(new char[size1]);
|
||||
std::unique_ptr<char[]> buf2(new char[size2]);
|
||||
std::unique_ptr<char[]> buf3(new char[size3]);
|
||||
std::unique_ptr<char[]> buf5(new char[size5]);
|
||||
file1.readBytes(buf1.get(), size1);
|
||||
file2.readBytes(buf2.get(), size2);
|
||||
file3.readBytes(buf3.get(), size3);
|
||||
file5.readBytes(buf5.get(), size5);
|
||||
|
||||
StaticJsonBuffer<100> jsonBuffer10;
|
||||
JsonObject &root1 = jsonBuffer10.parseObject(buf1.get());
|
||||
if (root1 == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error1");
|
||||
}
|
||||
StaticJsonBuffer<100> jsonBuffer11;
|
||||
JsonObject &root2 = jsonBuffer11.parseObject(buf2.get());
|
||||
if (root2 == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error2");
|
||||
}
|
||||
StaticJsonBuffer<100> jsonBuffer12;
|
||||
JsonObject &root3 = jsonBuffer12.parseObject(buf3.get());
|
||||
if (root3 == JsonObject::invalid())
|
||||
{
|
||||
Serial.println("Error3");
|
||||
}
|
||||
StaticJsonBuffer<50> jsonBuffer16;
|
||||
JsonObject &root5 = jsonBuffer16.parseObject(buf5.get());
|
||||
/*StaticJsonBuffer<300> jsonBuffer13;
|
||||
JsonObject& root4 = jsonBuffer13.createObject();
|
||||
JsonObject& ballast1 = root4.createNestedObject();
|
||||
root4["shour1"]=root1["shour1"];
|
||||
root4["smin1"]=root1["smin1"];
|
||||
root4["fadePeriod1"]=root1["fadePeriod1"];
|
||||
root4["shour2"]=root2["shour2"];
|
||||
root4["smin2"]=root2["smin2"];
|
||||
root4["fadePeriod2"]=root2["fadePeriod2"];
|
||||
root4["shour3"]=root3["shour3"];
|
||||
root4["smin3"]=root3["smin3"];
|
||||
root4["fadePeriod3"]=root3["fadePeriod3"];*/
|
||||
|
||||
DynamicJsonBuffer jsonBuffer(bufferSize);
|
||||
|
||||
JsonObject &root = jsonBuffer.createObject();
|
||||
|
||||
JsonArray &settings = root.createNestedArray("settings");
|
||||
|
||||
JsonObject &settings_0 = settings.createNestedObject();
|
||||
settings_0["shour"] = root1["shour1"];
|
||||
settings_0["fadePeriod"] = root1["fadePeriod1"];
|
||||
settings_0["smin"] = root1["smin1"];
|
||||
settings_0["ehour"] = root1["ehour"];
|
||||
settings_0["emin"] = root1["emin"];
|
||||
|
||||
JsonObject &settings_1 = settings.createNestedObject();
|
||||
settings_1["shour"] = root2["shour2"];
|
||||
settings_1["fadePeriod"] = root2["fadePeriod2"];
|
||||
settings_1["smin"] = root2["smin2"];
|
||||
settings_1["ehour"] = root2["ehour"];
|
||||
settings_1["emin"] = root2["emin"];
|
||||
|
||||
JsonObject &settings_2 = settings.createNestedObject();
|
||||
settings_2["shour"] = root3["shour3"];
|
||||
settings_2["fadePeriod"] = root3["fadePeriod3"];
|
||||
settings_2["smin"] = root3["smin3"];
|
||||
settings_2["ehour"] = root3["ehour"];
|
||||
settings_2["emin"] = root3["emin"];
|
||||
|
||||
root["manual"] = root5["manual"];
|
||||
/*root1.printTo(file4);
|
||||
root1.printTo(Serial);
|
||||
root2.printTo(file4);
|
||||
root2.printTo(Serial);
|
||||
root3.printTo(file4);
|
||||
root3.printTo(Serial);*/
|
||||
root.prettyPrintTo(Serial);
|
||||
root.prettyPrintTo(file4);
|
||||
// Serial.println("3");
|
||||
|
||||
file1.close();
|
||||
file2.close();
|
||||
file3.close();
|
||||
file4.close();
|
||||
file5.close();
|
||||
}
|
||||
/*void displaySettings()
|
||||
{
|
||||
File file = SPIFFS.open("/settingsFile.txt", "r");
|
||||
if (!file){
|
||||
Serial.println("Error reading settings file or file does not exist");
|
||||
} else {
|
||||
size_t size = file.size();
|
||||
if ( size == 0 ) {
|
||||
Serial.println("Settings file is empty");
|
||||
} else {
|
||||
std::unique_ptr<char[]> buf (new char[size]);
|
||||
file.readBytes(buf.get(), size);
|
||||
StaticJsonBuffer<200> jsonBuffer2;
|
||||
JsonObject& root = jsonBuffer2.parseObject(buf.get());
|
||||
if (!root.success()) {
|
||||
Serial.println("Error reading settings file");
|
||||
} else {
|
||||
Serial.println("Settings file loaded");
|
||||
root.prettyPrintTo(Serial);
|
||||
root.printTo(s);
|
||||
Serial.println("Settings sent to arduino");
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}*/
|
||||
void displayCombinedSettings()
|
||||
{
|
||||
File file = SPIFFS.open("/combinedSettingsFile.txt", "r");
|
||||
if (!file)
|
||||
{
|
||||
Serial.println("Error reading settings file or file does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Settings file exists");
|
||||
size_t size = file.size();
|
||||
if (size == 0)
|
||||
{
|
||||
Serial.println("Settings file is empty");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::unique_ptr<char[]> buf5(new char[size]);
|
||||
file.readBytes(buf5.get(), size);
|
||||
// StaticJsonBuffer<300> jsonBuffer;
|
||||
DynamicJsonBuffer jsonBuffer(bufferSize);
|
||||
JsonObject &root5 = jsonBuffer.parseObject(buf5.get());
|
||||
if (!root5.success())
|
||||
{
|
||||
Serial.println("Error reading combined settings file");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Settings file loaded");
|
||||
root5.prettyPrintTo(Serial);
|
||||
// digitalWrite(ESP_TO_ARDUINO_PIN,0);
|
||||
// analogWrite(ESP_TO_ARDUINO_PIN,255);
|
||||
root5.printTo(s);
|
||||
// digitalWrite(ESP_TO_ARDUINO_PIN,1);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
void handleManual()
|
||||
{
|
||||
File file = SPIFFS.open("/manualMode.txt", "w");
|
||||
StaticJsonBuffer<50> jsonBufferManual;
|
||||
JsonObject &root = jsonBufferManual.createObject();
|
||||
if (server.arg("manual") == "True")
|
||||
{
|
||||
root["manual"] = "True";
|
||||
}
|
||||
else
|
||||
{
|
||||
root["manual"] = "False";
|
||||
}
|
||||
root.printTo(file);
|
||||
file.close();
|
||||
combineSettings();
|
||||
// digitalWrite(ESP_TO_ARDUINO_PIN, 1);
|
||||
displayCombinedSettings();
|
||||
// digitalWrite(ESP_TO_ARDUINO_PIN,1);
|
||||
server.sendHeader("Location", "/manualMode.html"); // Redirect the client to the success page
|
||||
server.send(303);
|
||||
}
|
||||
void handleSettings()
|
||||
{
|
||||
if (server.arg("ballast").toInt() == 1)
|
||||
handleSettings1();
|
||||
else if (server.arg("ballast").toInt() == 2)
|
||||
handleSettings2();
|
||||
else if (server.arg("ballast").toInt() == 3)
|
||||
handleSettings3();
|
||||
displayCombinedSettings();
|
||||
server.sendHeader("Location", "/settings.html"); // Redirect the client to the success page
|
||||
server.send(303);
|
||||
}
|
||||
void handleSettings1()
|
||||
{
|
||||
saveSettings1();
|
||||
combineSettings();
|
||||
}
|
||||
void handleSettings2()
|
||||
{
|
||||
saveSettings2();
|
||||
combineSettings();
|
||||
}
|
||||
void handleSettings3()
|
||||
{
|
||||
saveSettings3();
|
||||
combineSettings();
|
||||
}
|
||||
void handleFileUpload()
|
||||
{ // upload a new file to the SPIFFS
|
||||
HTTPUpload &upload = server.upload();
|
||||
String path;
|
||||
if (upload.status == UPLOAD_FILE_START)
|
||||
{
|
||||
path = upload.filename;
|
||||
if (!path.startsWith("/"))
|
||||
path = "/" + path;
|
||||
if (!path.endsWith(".gz"))
|
||||
{ // The file server always prefers a compressed version of a file
|
||||
String pathWithGz = path + ".gz"; // So if an uploaded file is not compressed, the existing compressed
|
||||
if (SPIFFS.exists(pathWithGz)) // version of that file must be deleted (if it exists)
|
||||
SPIFFS.remove(pathWithGz);
|
||||
}
|
||||
Serial.print("handleFileUpload Name: ");
|
||||
Serial.println(path);
|
||||
fsUploadFile = SPIFFS.open(path, "w"); // Open the file for writing in SPIFFS (create if it doesn't exist)
|
||||
path = String();
|
||||
}
|
||||
else if (upload.status == UPLOAD_FILE_WRITE)
|
||||
{
|
||||
if (fsUploadFile)
|
||||
fsUploadFile.write(upload.buf, upload.currentSize); // Write the received bytes to the file
|
||||
}
|
||||
else if (upload.status == UPLOAD_FILE_END)
|
||||
{
|
||||
if (fsUploadFile)
|
||||
{ // If the file was successfully created
|
||||
fsUploadFile.close(); // Close the file again
|
||||
Serial.print("handleFileUpload Size: ");
|
||||
Serial.println(upload.totalSize);
|
||||
server.sendHeader("Location", "/success.html"); // Redirect the client to the success page
|
||||
server.send(303);
|
||||
}
|
||||
else
|
||||
{
|
||||
server.send(500, "text/plain", "500: couldn't create file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t lenght)
|
||||
{ // When a WebSocket message is received
|
||||
switch (type)
|
||||
{
|
||||
case WStype_DISCONNECTED: // if the websocket is disconnected
|
||||
Serial.printf("[%u] Disconnected!\n", num);
|
||||
break;
|
||||
case WStype_CONNECTED:
|
||||
{ // if a new websocket connection is established
|
||||
IPAddress ip = webSocket.remoteIP(num);
|
||||
Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
|
||||
rainbow = false; // Turn rainbow off when a new connection is established
|
||||
}
|
||||
break;
|
||||
case WStype_TEXT: // if new text data is received
|
||||
Serial.printf("[%u] get Text: %s\n", num, payload);
|
||||
if (payload[0] == '#')
|
||||
{ // we get RGB data
|
||||
uint32_t rgb = (uint32_t)strtol((const char *)&payload[1], NULL, 16); // decode rgb data
|
||||
int r = ((rgb >> 20) & 0x3FF); // 10 bits per color, so R: bits 20-29
|
||||
int g = ((rgb >> 10) & 0x3FF); // G: bits 10-19
|
||||
int b = rgb & 0x3FF; // B: bits 0-9
|
||||
|
||||
// analogWrite(LED_RED, r); // write it to the LED output pins
|
||||
// analogWrite(LED_GREEN, g);
|
||||
// analogWrite(LED_BLUE, b);
|
||||
}
|
||||
else if (payload[0] == 'R')
|
||||
{ // the browser sends an R when the rainbow effect is enabled
|
||||
rainbow = true;
|
||||
}
|
||||
else if (payload[0] == 'N')
|
||||
{ // the browser sends an N when the rainbow effect is disabled
|
||||
rainbow = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*__________________________________________________________HELPER_FUNCTIONS__________________________________________________________*/
|
||||
|
||||
String formatBytes(size_t bytes)
|
||||
{ // convert sizes in bytes to KB and MB
|
||||
if (bytes < 1024)
|
||||
{
|
||||
return String(bytes) + "B";
|
||||
}
|
||||
else if (bytes < (1024 * 1024))
|
||||
{
|
||||
return String(bytes / 1024.0) + "KB";
|
||||
}
|
||||
else if (bytes < (1024 * 1024 * 1024))
|
||||
{
|
||||
return String(bytes / 1024.0 / 1024.0) + "MB";
|
||||
}
|
||||
}
|
||||
|
||||
String getContentType(String filename)
|
||||
{ // determine the filetype of a given filename, based on the extension
|
||||
if (filename.endsWith(".html"))
|
||||
return "text/html";
|
||||
else if (filename.endsWith(".css"))
|
||||
return "text/css";
|
||||
else if (filename.endsWith(".js"))
|
||||
return "application/javascript";
|
||||
else if (filename.endsWith(".ico"))
|
||||
return "image/x-icon";
|
||||
else if (filename.endsWith(".gz"))
|
||||
return "application/x-gzip";
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
void setHue(int hue)
|
||||
{ // Set the RGB LED to a given hue (color) (0° = Red, 120° = Green, 240° = Blue)
|
||||
hue %= 360; // hue is an angle between 0 and 359°
|
||||
float radH = hue * 3.142 / 180; // Convert degrees to radians
|
||||
float rf, gf, bf;
|
||||
|
||||
if (hue >= 0 && hue < 120)
|
||||
{ // Convert from HSI color space to RGB
|
||||
rf = cos(radH * 3 / 4);
|
||||
gf = sin(radH * 3 / 4);
|
||||
bf = 0;
|
||||
}
|
||||
else if (hue >= 120 && hue < 240)
|
||||
{
|
||||
radH -= 2.09439;
|
||||
gf = cos(radH * 3 / 4);
|
||||
bf = sin(radH * 3 / 4);
|
||||
rf = 0;
|
||||
}
|
||||
else if (hue >= 240 && hue < 360)
|
||||
{
|
||||
radH -= 4.188787;
|
||||
bf = cos(radH * 3 / 4);
|
||||
rf = sin(radH * 3 / 4);
|
||||
gf = 0;
|
||||
}
|
||||
int r = rf * rf * 1023;
|
||||
int g = gf * gf * 1023;
|
||||
int b = bf * bf * 1023;
|
||||
|
||||
// analogWrite(LED_RED, r); // Write the right color to the LED output pins
|
||||
// analogWrite(LED_GREEN, g);
|
||||
// analogWrite(LED_BLUE, b);
|
||||
}
|
39
src/sketch_oct17esp.hpp
Executable file
39
src/sketch_oct17esp.hpp
Executable file
@ -0,0 +1,39 @@
|
||||
// /* This file was automatically generated. Do not edit! */
|
||||
// #undef INTERFACE
|
||||
void handleSettings3();
|
||||
void handleSettings2();
|
||||
void handleSettings1();
|
||||
void combineSettings();
|
||||
void saveSettings3();
|
||||
void saveSettings2();
|
||||
void saveSettings1();
|
||||
String getContentType(String filename);
|
||||
bool handleFileRead(String path);
|
||||
void handleManual();
|
||||
void handleSettings();
|
||||
void handleNotFound();
|
||||
void handleFileUpload();
|
||||
void webSocketEvent(uint8_t num,WStype_t type,uint8_t *payload,size_t lenght);
|
||||
String formatBytes(size_t bytes);
|
||||
extern int hue;
|
||||
void setHue(int hue);
|
||||
void displayCombinedSettings();
|
||||
void loop();
|
||||
extern unsigned long prevMillis;
|
||||
extern bool rainbow;
|
||||
void startServer();
|
||||
void startMDNS();
|
||||
void startWebSocket();
|
||||
void startSPIFFS();
|
||||
void startOTA();
|
||||
void startWiFi();
|
||||
void setup();
|
||||
extern const char *mdnsName;
|
||||
extern byte previousArduinoState;
|
||||
extern byte currentArduinoState;
|
||||
extern const char *OTAPassword;
|
||||
extern const char *OTAName;
|
||||
extern const char *password;
|
||||
extern const char *ssid;
|
||||
extern File fsUploadFile;
|
||||
extern ESP8266WiFiMulti wifiMulti;
|
11
test/README
Executable file
11
test/README
Executable file
@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
BIN
website-zipped_bak/index.html.gz
Executable file
BIN
website-zipped_bak/index.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/ledcontrol.html.gz
Executable file
BIN
website-zipped_bak/ledcontrol.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/main.css.gz
Executable file
BIN
website-zipped_bak/main.css.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/manifest.json.gz
Executable file
BIN
website-zipped_bak/manifest.json.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/manualMode-ajax.html.gz
Executable file
BIN
website-zipped_bak/manualMode-ajax.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/manualMode.html.gz
Executable file
BIN
website-zipped_bak/manualMode.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/menu.html.gz
Executable file
BIN
website-zipped_bak/menu.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/nunito-regular-webfont.woff.gz
Executable file
BIN
website-zipped_bak/nunito-regular-webfont.woff.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/nunito-regular-webfont.woff2.gz
Executable file
BIN
website-zipped_bak/nunito-regular-webfont.woff2.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/settings-ajax.html.gz
Executable file
BIN
website-zipped_bak/settings-ajax.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/settings-success.html.gz
Executable file
BIN
website-zipped_bak/settings-success.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/settings.html.gz
Executable file
BIN
website-zipped_bak/settings.html.gz
Executable file
Binary file not shown.
BIN
website-zipped_bak/success.html.gz
Executable file
BIN
website-zipped_bak/success.html.gz
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user