Hi, I'm writing a Hydroponic Automation System but i got this issue using a WeMos D1 Wifi board that spits out an error here's the complete code below, i'm not sure why what i think it is a watch dog reset?
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
#include <DHT.h>
#include <Arduino.h>
#define DHTPIN D6 //D2 pin is dead
#define DHTTYPE DHT11 // DHT 11 temperature and humidity sensor
//DHT temperature and humidity
DHT dht(DHTPIN, DHTTYPE);
//wifi credentials
const char* ssid = "Wifi";
const char* password = "P@ssw0rd123";
ESP8266WebServer server(80);
StaticJsonDocument<256> jsonDocument;
char buffer[256];
//device information
char* moduleName = "ControlModule";
char* moduleID = "WMD105222022";
char* moduleType = "Prototype";
char* firmwareVersion = "1.15";
//temperature and humidity variables
double temperature;
double humidity;
//phSensor data sample
int samples = 10;
float adc_resolution = 1024.0;
//water level variable
int full; // green
int half; // blue
int f;
int h;
int v=100; //base voltage variable
//Mux/Multiplexer control pins
int s0 = D8;
int s1 = D9;
int s2 = D10;
int s3 = D11;
//Mux/multiplexer in SIG or signal pin
int SIG_pin = A0;
//webserver routing
void setup_routing() {
server.on("/device", deviceData);
server.on("/data", getData);
server.begin();
}
//water level sensor voltage potential clac
float ph (float voltage) {
return 7 + ((2.5 - voltage) / 0.18);
}
//generating json data for device api
void create_json(char *tag, double value, char *unit) {
jsonDocument.clear();
jsonDocument["value"] = value;
jsonDocument["unit"] = unit;
serializeJson(jsonDocument, buffer);
}
void create_device(char *moduleID, char *moduleType, char *firmwareVersion) {
jsonDocument.clear();
jsonDocument["id"] = moduleID;
jsonDocument["type"] = moduleType;
jsonDocument["firmware"] = firmwareVersion;
serializeJson(jsonDocument, buffer);
}
void add_json_device(char *moduleID, char *moduleType, char *firmwareVersion) {
JsonObject device = jsonDocument.createNestedObject("device");
device["id"] = moduleID;
device["type"] = moduleType;
device["firmware"] = firmwareVersion;
}
void add_json_object(char *tag, double value, char *unit) {
JsonObject obj = jsonDocument.createNestedObject(tag);
obj["value"] = serialized(String(value,2));
obj["unit"] = unit;
}
//reading sensor for all sensor data
void read_sensor_data() {
//temperature & humdity
temperature = dht.readTemperature();
humidity = dht.readHumidity();
//ph sensor
int measurings=0;
for (int i = 0; i < samples; i++)
{
measurings += analogRead(readMux(0));
delay(10);
}
//water level voltage potential
float voltage = 5 / adc_resolution * measurings/samples;
//water level
full = readMux(1);
half = readMux(2);
pinMode(full, INPUT);
pinMode(half, INPUT);
f=analogRead(full);
h=analogRead(half);
//console output for debugging
Serial.print("Green Wire Value: ");
Serial.println(f);
Serial.print("Blue Wire Value:");
Serial.println(h);
Serial.print("-> Temperature: ");
Serial.print(temperature);
Serial.print(", Humidity: ");
Serial.print(humidity);
Serial.print(", pH= ");
Serial.print(ph(voltage));
Serial.print(", WaterLevel = ");
//conditional statement for water level
if(f<400 && h<400 && f!=0 && h!=0){
Serial.println("Tank is Full");
}else if(f>400 && f!=0 && h<400 && h!=0){
Serial.println("Tank is Half");
}else if(f== 0 && h==0){
Serial.println("Tank is Critical");
}else{
Serial.println("No Data");
}
}
//generating json data
void deviceData() {
create_device(moduleID, moduleType, firmwareVersion);
server.send(200, "application/json", buffer);
}
//passing sensor data to generate json data for api use
void getData() {
jsonDocument.clear();
add_json_device(moduleID, moduleType, firmwareVersion);
// add_json_device("type", moduleType);
add_json_object("temperature", temperature, "°C");
add_json_object("humidity", humidity, "%");
serializeJson(jsonDocument, buffer);
server.send(200, "application/json", buffer);
}
void setup_task() {
read_sensor_data();
}
void setup(void){
//code needs to be run once
Serial.begin(115200);
//setting mux control pins
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting...");
while (WiFi.status() != WL_CONNECTED){
}
Serial.println(F("DHT11 test!"));
dht.begin();
Serial.print("Connected! IP Address: ");
Serial.println(WiFi.localIP());
setup_task();
setup_routing();
}
void loop(void){
//code for runs on loop
setup_task();
server.handleClient();
}
//Mux/Multiplexer truth table for assigning specific channel funtion
int readMux(int channel){
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[16][4]={
{0,0,0,0}, //channel 0
{1,0,0,0}, //channel 1
{0,1,0,0}, //channel 2
{1,1,0,0}, //channel 3
{0,0,1,0}, //channel 4
{1,0,1,0}, //channel 5
{0,1,1,0}, //channel 6
{1,1,1,0}, //channel 7
{0,0,0,1}, //channel 8
{1,0,0,1}, //channel 9
{0,1,0,1}, //channel 10
{1,1,0,1}, //channel 11
{0,0,1,1}, //channel 12
{1,0,1,1}, //channel 13
{0,1,1,1}, //channel 14
{1,1,1,1} //channel 15
};
//loop through the 4 sig
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[channel][i]);
}
//read the value at the SIG pin
int val = analogRead(SIG_pin);
//return the value
return val;
}
and here's what i'm getting from the serial monitor
05:10:44.266 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
05:10:44.298 ->
05:10:44.298 -> Soft WDT reset
05:10:44.298 ->
05:10:44.298 -> >>>stack>>>
05:10:44.298 ->
05:10:44.298 -> ctx: cont
05:10:44.298 -> sp: 3ffffda0 end: 3fffffc0 offset: 01a0
05:10:44.298 -> 3fffff40: 40205f60 3ffe89bf 3ffeec10 40205f6c
05:10:44.298 -> 3fffff50: 4023ef16 3ffeec10 3ffeebd4 00000001
05:10:44.298 -> 3fffff60: 402400fb 0000000d 3ffeec10 4020643c
05:10:44.298 -> 3fffff70: 3ffef674 40204ae0 00000000 40206488
05:10:44.298 -> 3fffff80: 3fffdad0 3ffeebd4 3ffeec10 40201bd5
05:10:44.331 -> 3fffff90: feefeffe feefeffe feefeffe feefeffe
05:10:44.331 -> 3fffffa0: feefeffe 00000000 3ffeec88 40207e20
05:10:44.331 -> 3fffffb0: feefeffe feefeffe 3ffe8604 40100d3d
05:10:44.331 -> <<<stack<<<
05:10:44.331 ->
05:10:44.331 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
05:10:44.364 ->
05:10:44.364 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
05:10:44.364 ->
05:10:44.364 -> load 0x4010f000, len 3460, room 16
05:10:44.364 -> tail 4
05:10:44.364 -> chksum 0xcc
05:10:44.364 -> load 0x3fff20b8, len 40, room 4
05:10:44.364 -> tail 4
05:10:44.364 -> chksum 0xc9
05:10:44.364 -> csum 0xc9
05:10:44.364 -> v0004bca0
05:10:44.364 -> ~ld
05:10:44.427 ->
05:10:44.427 -> Connecting...