|
|
@ -8,61 +8,23 @@ |
|
|
|
#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]; |
|
|
|
static char rtcDate[10]; |
|
|
|
|
|
|
|
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)) + 100; |
|
|
|
const unsigned int delayInMillisSensors = 750 / (1 << (12 - SENSOR_RESOLUTION)); |
|
|
|
|
|
|
|
ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
|
|
|
|
|
|
|
@ -77,7 +39,6 @@ const char *password = "thereisnospoon"; // The password required to connect t |
|
|
|
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
|
|
|
@ -118,69 +79,6 @@ void setup() |
|
|
|
|
|
|
|
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(); |
|
|
@ -228,34 +126,32 @@ void loop() |
|
|
|
} |
|
|
|
|
|
|
|
// 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); |
|
|
|
} |
|
|
|
// if (s.available() > 0)
|
|
|
|
// {
|
|
|
|
// Serial << F("Received JSON from arduino") << endl;
|
|
|
|
// Serial << F("Inside second if ") << endl;
|
|
|
|
// StaticJsonBuffer<100> jsonBuffer;
|
|
|
|
// // DynamicJsonBuffer jsonBuffer(100);
|
|
|
|
// Serial << "S available = " << s.available();
|
|
|
|
|
|
|
|
// JsonObject &root = jsonBuffer.parseObject(s);
|
|
|
|
// JsonArray &lcd_data = root["lcdData"];
|
|
|
|
// // lcd_data[0];
|
|
|
|
// // char a[10];
|
|
|
|
// sprintf(rtcDate, lcd_data[1]);
|
|
|
|
|
|
|
|
// 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);
|
|
|
@ -277,14 +173,14 @@ void loop() |
|
|
|
// }
|
|
|
|
if (millis() - lastTempRequest >= delayInMillisSensors) |
|
|
|
{ |
|
|
|
char b[10]; |
|
|
|
char str_temp[6]; |
|
|
|
// char b[10];
|
|
|
|
// char str_temp[6];
|
|
|
|
// saveTemperatureJson();
|
|
|
|
StaticJsonBuffer<200> jsonBuffer; |
|
|
|
JsonObject &root = jsonBuffer.createObject(); |
|
|
|
if (root == JsonObject::invalid()) |
|
|
|
{ |
|
|
|
Serial.println("Error"); |
|
|
|
Serial.println("Error creating temperature json"); |
|
|
|
} |
|
|
|
JsonArray &temperatures = root.createNestedArray("temperatures"); |
|
|
|
temperatures.add(sensors.getTempCByIndex(0)); |
|
|
@ -311,8 +207,8 @@ void startWiFi() |
|
|
|
Serial.println("\" started\r\n"); |
|
|
|
|
|
|
|
wifiMulti.addAP("Rohan-2", "coldpark735"); // add Wi-Fi networks you want to connect to
|
|
|
|
wifiMulti.addAP("Rohan-1", "Mir@1932"); |
|
|
|
wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); |
|
|
|
// wifiMulti.addAP("Rohan-1", "Mir@1932");
|
|
|
|
wifiMulti.addAP("Rohan-3", "coldpark735"); |
|
|
|
|
|
|
|
Serial.print(F("MAC: ")); |
|
|
|
Serial.println(WiFi.macAddress()); |
|
|
@ -420,6 +316,10 @@ void startServer() |
|
|
|
server.send(200, "application/json", temperaturesJson); |
|
|
|
}); |
|
|
|
|
|
|
|
server.on("/api/get/date", HTTP_GET, []() { |
|
|
|
server.send(200, "text/plain", rtcDate); |
|
|
|
}); |
|
|
|
|
|
|
|
server.begin(); // start the HTTP server
|
|
|
|
Serial.println("HTTP server started."); |
|
|
|
} |
|
|
@ -775,8 +675,8 @@ void handleSettings() |
|
|
|
else if (server.arg("ballast").toInt() == 3) |
|
|
|
handleSettings3(); |
|
|
|
displayCombinedSettings(); |
|
|
|
server.sendHeader("Location", "/settings.html"); // Redirect the client to the success page
|
|
|
|
server.send(303); |
|
|
|
// server.sendHeader("Location", "/settings.html"); // Redirect the client to the success page
|
|
|
|
server.send(200); |
|
|
|
} |
|
|
|
void handleSettings1() |
|
|
|
{ |
|
|
|