HELP ME esp8266 and read analog


#1

hello what read info fron analog 0 in cayenne …no detect pin a0
// 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>
// WiFi network info.
char ssid[] = “Hostal las Ventas”;
char wifiPassword[] = “xxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] =
char password[] = "
char clientID[] = "
unsigned long lastMillis = 0;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(A0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}


#2

which esp8266 device you are using? you need to start this if using a wemos https://github.com/wemos/D1_mini_Examples/blob/master/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino


#3

nodencu v3 i copy script and cayenne no detect


#4

what are you trying to do with nodemcu and analog input. Do you want to display the analog input value on the cayenne dashboard? which sensor you have connected to analog pin?


#5

yes for all aswers


#6

read water conductivity


#7

@luisvaljun8 you need to provide more detail if you want some help. kindly provide some link to the sensor you are using.


#8

https://es.aliexpress.com/item/Free-shipping-soil-the-hygrometer-detection-module-robot-intelligent-car-soil-moisture-sensor-for-arduino/1878979122.html?src=google&albslr=220833420&isdl=y&aff_short_key=UneMJZVf&source={ifdyn:dyn}{ifpla:pla}{ifdbm:DBM&albch=DID}&src=google&albch=shopping&acnt=768-202-3196&isdl=y&albcp=1418125117&albag=53860668937&slnk=&trgt=296303633664&plac=&crea=es1878979122&netw=g&device=c&mtctp=&aff_platform=google&gclid=CjwKCAjwyMfZBRAXEiwA-R3gMxRVySbvsgz_YvlGKZrJDcJkzBsyu3ImuqaSwFeYvqtU8lbLLITHThoCZfkQAvD_BwE&gclsrc=aw.ds

this sensor


#9

thank you. now follow this tutorial and see if you can get the reading from the sensor. once you get reading we will move to cayenne code. first try this http://www.instructables.com/id/Interface-Moisture-Sensor-With-NodeMCU/


#10

yes read data


#11

can you share the serial monitor output and code, so accordingly i can suggest the next step.


#12

com4 9600


#13

code is up post friend


#14

i wanted to see the sensor value output in the serial monitor.

Next, you have add a new device to cayenne dashboard using Adding a New Device using MQTT
Once you device is connected, upload the below code,

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

int sense_Pin = 0; // sensor input at Analog pin A0

int value = 0;
void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);

}
void loop() {
  Cayenne.loop();
  Serial.print("MOISTURE LEVEL : ");
  value = analogRead(sense_Pin);
  value = value / 10;
  Serial.println(value);

}
CAYENNE_OUT_DEFAULT()
{
  Cayenne.virtualWrite(1, value, "analog_sensor", "null");
}