Hello friends, I have this code to read the data of a rain gauge, what it does is count the times that a magnet passes in front of a reed switch and calculates the fallen L / m2.
Can you help me make a code that works with Cayenne connected via MQTT?
const int SENSOR=D6;
const int umbraltiempo=300;
volatile int ISRContador = 0;
int contador = 0;
float litros=0;
long tiempocontador=0;
long tiempohora =0;
which device are you using to connect to internet. we have couple of example for different types of boards and devices. Select the appropriate code and add your rain gauge sensor code into it. Then you send the sensor data using Cayenne.virtualWrite(3, litros, "rain_level", "cm");
// This example shows how to connect to Cayenne using an ESP8266 and send / receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.
// # define CAYENNE_DEBUG #define CAYENNE_PRINT Serial #include <CayenneMQTTESP8266.h>
const int SENSOR = 2;
const int thresholdtime = 300;
volatile int ISRContador = 0;
int counter = 0;
float liters = 0;
long counting time = 0;
long timehora = 0;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “5a3596-8221-599f77add412”;
char password = “9a4f400584a42a4f47f840e68648”;
char clientID = “53921-599f77add412”;
First I would like to know if it is well raised. I use ESP8266 - 07.
In the Serial Monitor I am informed of the error “ISR not in IRAM!”
From what I see it has to do with the handling of interruptions.
It happens that I have no idea if the code is correct and that is why the problem.
I will appreciate your attention.
Thank you for your response, I ask you to be patient, I still do not know very well the rules of the forum.
I am using an ESP8266-07 board, maybe all the problems come for that.
I loaded the sketch you passed me.
The first problem appears with the definition of SENSOR, it tells me “‘D6’ was not declared in this scope”, I changed it to “const int SENSOR = 2;”
After starting the system, in Cayenne Dashboar the device is Off Line and this appears repeatedly in the Monitor Serie:
i just modified the code you posted in the very first. i thought you had it working with esp8266-07. So first get your rain guage sensor working with esp-07 with out cayenne.
Now the counter works, but does not calculate “litros”, it may have some bad parameter. I pass the complete code. It seems that it does not work in “void counterLiters ()”
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
const int SENSOR=2;
const int umbraltiempo=300;
volatile int ISRContador = 0;
int contador = 0;
float litros=0;
long tiempocontador=0;
long tiempohora =0;
// WiFi network info.
char ssid[] = "Mapear 2.4 GHz";
char wifiPassword[] = "03472977";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "5a3596e0-f12b-99f77add412";
char password[] = "9a4f400584a42a06644668648";
char clientID[] = "a8ed11c0-f8c7b6757b1bf";
unsigned long lastMillis = 0;
void ICACHE_RAM_ATTR contadorLitros();
void setup() {
pinMode(SENSOR, INPUT_PULLUP);
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
attachInterrupt(digitalPinToInterrupt(SENSOR),contadorLitros,FALLING);
}
void loop() {
Cayenne.loop();
void contadorLitros()
{
if(millis()>(tiempocontador+umbraltiempo))
{
ISRContador++;
tiempocontador=millis();
Serial.print(ISRContador);
}
}
if (millis()<tiempohora)
{
tiempohora=0;
}
if (millis()-tiempohora>3600000UL) {
tiempohora = millis();
Serial.print(tiempohora);
litros=ISRContador * 0.5;
Serial.print("Litros por m2 caidos en un minuto (L/m2): ");
Serial.println(litros);
ISRContador= 0;
contador= 0;
}
}
CAYENNE_OUT_DEFAULT()
{
Cayenne.virtualWrite (3, litros, "rain_level", "cm");
}
before trying the cayenne code, first see if you can get the rain gauge sensor working with esp-07. And looking at the code, it looks like it will never get upload and give a compile error.
Just remove the cayenne code and get the sensor reading on the serial monitor.