145 lines
4 KiB
C++
145 lines
4 KiB
C++
/*
|
|
*
|
|
* CanGrow - an OpenSource growcontroller firmware (for cannabis)
|
|
*
|
|
*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2024 DeltaLima
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to
|
|
* deal in the Software without restriction, including without limitation the
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*
|
|
*/
|
|
|
|
|
|
/*
|
|
* CanGrow includes
|
|
*/
|
|
|
|
#include "include/CanGrow.h"
|
|
#include "include/CanGrow_Core.h"
|
|
|
|
/*
|
|
* Libraries
|
|
*/
|
|
|
|
// * ESP8266 *
|
|
#ifdef ESP8266
|
|
#include <ESP8266WiFi.h>
|
|
#endif
|
|
|
|
// * ESP32 *
|
|
#ifdef ESP32
|
|
#include <WiFi.h>
|
|
#endif
|
|
|
|
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI
|
|
#include <SPI.h>
|
|
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire
|
|
#include <Wire.h>
|
|
// https://github.com/lacamera/ESPAsyncWebServer
|
|
#include <ESPAsyncWebServer.h>
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
#include <ArduinoJson.h>
|
|
// https://github.com/PaulStoffregen/Time
|
|
#include <TimeLib.h>
|
|
// arduino-core for esp8266 and esp32
|
|
#include "LittleFS.h"
|
|
|
|
|
|
void setup() {
|
|
// define output for onboard LED/WIPE pin
|
|
pinMode(PinWIPE, OUTPUT);
|
|
|
|
// Start Serial
|
|
Serial.begin(115200);
|
|
|
|
// Write a line before doing serious output, because before there is some garbage in serial
|
|
// whats get the cursor somewhere over the place
|
|
Serial.println("420");
|
|
Serial.print(".:: CanGrow firmware v");
|
|
Serial.print(CanGrowVer);
|
|
Serial.print(" build ");
|
|
Serial.print(CanGrowBuild);
|
|
Serial.println(" starting ::.");
|
|
|
|
|
|
Serial.print(":: To format LittleFS, pull ");
|
|
Serial.print(PinWIPE);
|
|
Serial.println("(PinWIPE) to LOW - NOW! (2 seconds left) ::");
|
|
|
|
// blink with the onboard LED on D4 (PinWIPE)
|
|
for(byte i = 0; i <= 6 ; i++) {
|
|
if(i % 2) {
|
|
digitalWrite(PinWIPE, LOW);
|
|
} else {
|
|
digitalWrite(PinWIPE, HIGH);
|
|
}
|
|
delay(333);
|
|
}
|
|
// set back to HIGH because thats the default
|
|
digitalWrite(PinWIPE, HIGH);
|
|
//delay(2000);
|
|
|
|
// read status from PinWIPE to WIPE
|
|
// when PinWIPE is set to LOW, format LittleFS
|
|
if(digitalRead(PinWIPE) == LOW) {
|
|
Serial.println("!! formatting LittleFS !!");
|
|
LittleFS.format();
|
|
Panic();
|
|
}
|
|
|
|
|
|
Serial.println(":: initialise LittleFS ::");
|
|
if(LittleFS.begin()) {
|
|
Serial.println(":: LittleFS successfully initialised ::");
|
|
} else {
|
|
Serial.println("!! LittleFS failed initialising !!");
|
|
}
|
|
|
|
// read the configfile from LittleFS
|
|
File lfs_configfile = LittleFS.open(configfile, "r");
|
|
if(!lfs_configfile) {
|
|
Serial.println("!! LittleFS: config.json not found, creating it !!");
|
|
lfs_configfile = LittleFS.open(configfile, "w");
|
|
if(lfs_configfile) {
|
|
Serial.println(":: LittleFS: config.json successfully created ::");
|
|
// write into the file
|
|
lfs_configfile.print("{test: }");
|
|
// close the file
|
|
lfs_configfile.close();
|
|
}
|
|
} else {
|
|
Serial.println(":: LittleFS: config.json successfully opened ::");
|
|
String configfile_content = "";
|
|
|
|
while (lfs_configfile.available()) {
|
|
configfile_content += (char)lfs_configfile.read();
|
|
}
|
|
|
|
Serial.println("-- LittleFS: config.json content --");
|
|
Serial.println(configfile_content);
|
|
Serial.println("-- LittleFS: config.json end --");
|
|
}
|
|
|
|
}
|
|
|
|
void loop() {
|
|
|
|
}
|