#include <ThingSpeak.h>
#include <WiFiManager.h>
#include "DHT.h"
#define DHTPIN 14
#define DHTTYPE DHT11
#define TRIGGER_PIN 10
#define ctra 4
#define ctrb 20
#define ctrc 19
unsigned long myChannelNumber = 1729841;
const char * myWriteAPIKey = "xxxxxxxxxxxxxxxxxxxxx";
DHT dht(DHTPIN, DHTTYPE);
const float S_analog = 1023.0;
int co, nh3;
float no2;
void setup() {
WiFi.mode(WIFI_STA);
Serial.begin(115200);
WiFiManager wm;
pinMode(TRIGGER_PIN, INPUT);
bool res;
res = wm.autoConnect("beppeparini.in", "salubrita");
pinMode(ctra, OUTPUT);
pinMode(ctrb, OUTPUT);
pinMode(ctrc, OUTPUT);
dht.begin();
if (!res) {
Serial.println("Failed to connect");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
void loop() {
//checkButton();
float h = dht.readHumidity();
float t = dht.readTemperature();
digitalWrite(ctra, LOW);
digitalWrite(ctrb, LOW);
digitalWrite(ctrc, LOW);
int MQ135 = analogRead(A0);
delay(5000);
digitalWrite(ctra, LOW);
digitalWrite(ctrb, LOW);
digitalWrite(ctrc, HIGH);
int MQ138 = analogRead(A0);
delay(5000);
digitalWrite(ctra, LOW);
digitalWrite(ctrb, HIGH);
digitalWrite(ctrc, LOW);
co = map (analogRead(A0), 0, S_analog, 1, 1000);
delay(5000);
digitalWrite(ctra, LOW);
digitalWrite(ctrb, HIGH);
digitalWrite(ctrc, HIGH);
nh3 = map (analogRead(A0), 0, S_analog, 1, 500);
delay(5000);
digitalWrite(ctra, HIGH);
digitalWrite(ctrb, LOW);
digitalWrite(ctrc, LOW);
no2 = (map (lettura, 0, S_analog, 5, 1000)) / 100.0 ;
delay(5000);
Serial.println(t);
Serial.println(h);
Serial.println(MQ135);
Serial.println(MQ138);
Serial.println(co);
Serial.println(nh3);
Serial.println(no2);
ThingSpeak.setField(1, t);
ThingSpeak.setField(2, h);
ThingSpeak.setField(3, MQ135);
ThingSpeak.setField(4, MQ138);
ThingSpeak.setField(5, co);
ThingSpeak.setField(6, nh3);
ThingSpeak.setField(7, no2);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(30000);
}
/*
void checkButton(){
if ( digitalRead(TRIGGER_PIN) == LOW ) {
delay(50);
if( digitalRead(TRIGGER_PIN) == LOW ){
Serial.println("Button Pressed");
// still holding button for 3000 ms, reset settings, code not ideaa for production
delay(3000); // reset delay hold
if( digitalRead(TRIGGER_PIN) == LOW ){
Serial.println("Button Held");
Serial.println("Erasing Config, restarting");
wm.resetSettings();
ESP.restart();
}
// start portal w delay
Serial.println("Starting config portal");
wm.setConfigPortalTimeout(120);
if (!wm.startConfigPortal("beppeparini.in","salubrita")) {
Serial.println("failed to connect or hit timeout");
delay(3000);
// ESP.restart();
} else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
}
}*/
Buonpomeriggio,
ho un problema con questo codice.
Viene compilato e caricato.
la scheda in questione è un nodemcu v3.
qui sotto l'errore che mi da in seriale:
load 0x4010f000, len 3460, room 16 tail 4 chksum 0xcc load 0x3fff20b8, len 40, room 4 tail 4 chksum 0xc9 csum 0xc9 v00058260