Temperature measurement

so, there are no more issue with disconnect and temperature?

which setting are you referring to?

No for now…

I don’t know))))

if it is working then why do you want to change any more settings?

Do you thing it is all? no )))))
I have problem with NODE MCU. When I bought it, I try to connect it to Cayenne, every thing was working, but now I couldn’t upload the code.

I don’t won’t to change, I mean if it doesn’t work in my country house, but it is working in my apartment in town, maybe its because of some different settings in wifi router?

For nodemcu you need to use different header and code Adding a New Device using MQTT

I done this, same error

may be its because of the version of Arduino ide?

can you share the code you are using now?

/*
This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Install the ESP8266SerialLibrary.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library) from the Cayenne extras/libraries
   folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to compile this example.
2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial1 hardware serial pins available on the Mega. You can also try 
   using a software serial, though it may be less stable.
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
4. Set the network name and password.
5. Compile and upload the sketch.
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.
*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <DHT.h>
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

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

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial
#define SENSOR_PIN1 A0
#define VIRTUAL_CHANNEL1 1
#define SENSOR_PIN2 A1
#define VIRTUAL_CHANNEL2 2
#define DHTPIN 5     // Digital pin connected to the DHT sensor
#define RELEY_VIRTUAL_CHANNEL 9
#define ACTUATOR_PIN 4
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

#define TEMPERATURE_VIRTUAL_CHANNEL 7
#define HUMIDITY_VIRTUAL_CHANNEL 8


DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor.
ESP8266 wifi(&EspSerial);

void setup()
{
  pinMode(ACTUATOR_PIN, OUTPUT);


  Serial.begin(9600);
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(9600);
  delay(10);

  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
  dht.begin();
}

void loop()
{
  Cayenne.loop();
}
CAYENNE_IN(RELEY_VIRTUAL_CHANNEL)
{
  // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
  if (getValue.asInt() == 0) {
    digitalWrite(ACTUATOR_PIN, LOW);
  }
  else {
    digitalWrite(ACTUATOR_PIN, HIGH);
  }
} 
CAYENNE_OUT(TEMPERATURE_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(TEMPERATURE_VIRTUAL_CHANNEL, dht.readTemperature(), "temp", "c");
}

// This function is called at intervals to send humidity sensor data to Cayenne.
CAYENNE_OUT(HUMIDITY_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(HUMIDITY_VIRTUAL_CHANNEL, dht.readHumidity(), "rel_hum", "p");
}
// 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()
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN1));

Cayenne.virtualWrite(VIRTUAL_CHANNEL2, analogRead(SENSOR_PIN2));
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, 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");
}

this is not the correct code. look at the topic i shared above.

But if I use some basic code like that:
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
delay(2000); // Wait for two seconds (to demonstrate the active low LED)
}

all good

go through the entire topic once again step by step and you will understand your mistake.

Now its working
thank you so much!
now we could close this topic. if I will need more help, how could I connect with YOU?

1 Like

you can connect me with here on forum or join http://slack.mydevices.com/

Thanks man. Have a good one. till next time))))

1 Like