Help with newbi NodeMCU


#1

Hello, im new in arduino and cayenne thing and want to learning.
im building with nodemcu sensor and relay stuff but keep getting message “[160758] Connecting to arduino.mydevices.com:”

and then get this message : ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset with debug on,

,
can anyone help me to solve this problem?

Here is my code :

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#define CAYENNE_DEBUG
#include <ESP8266WiFi.h>
#include “CayenneDefines.h” // Wifi Sensors
#include “BlynkSimpleEsp8266.h”
#include “CayenneWiFiClient.h”
#include <DHT.h> // DHT Sensors

#define Pin A0 // Soil Sensors Analog
#define DHTPIN 5 // DHT Pin Sensor
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

char token[] = “”;
char ssid[] = “”;
char password[] = “”;

void setup(void)
{
// initialize digital pin 2 as an output.
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
Serial.begin(115200);
// dht.begin();
Cayenne.begin(token, ssid, password); //Cayenne
}

void loop(){
{
Cayenne.run();
}
delay (500);
int h = dht.readHumidity();
int t = dht.readTemperature();
Serial.print(“Temeperature : “);
Serial.print(t);
Serial.println(” C”);
Serial.print(“Humidity : “);
Serial.print(h);
Serial.println(” %”);
int x = analogRead(A0);
int y = map(x, 945, 380 , 0, 100);
Serial.print("Moisture : ");
Serial.println(y);
Cayenne.virtualWrite(V1,y);
}
// CAYENNE_OUT(V1)
//{
// Cayenne.virtualWrite(V1,y);
//}
CAYENNE_OUT(V2)
{
Cayenne.virtualWrite(V2, dht.readTemperature());
}
CAYENNE_OUT(V3)
{
Cayenne.virtualWrite(V3, dht.readHumidity());
}

//----------------- RELAY LINES
// This function will be called every time a Dashboard widget writes a value to Virtual Pin 2.
CAYENNE_IN(V5) //------------------- RELAY 1
{
CAYENNE_LOG(“Got a value: %s”, getValue.asStr());
int i = getValue.asInt();

if (i == 0)
{
digitalWrite(D5, HIGH);
}
else
{
digitalWrite(D5, LOW);
}
}
CAYENNE_IN(V6) //------------------- RELAY 2
{
CAYENNE_LOG(“Got a value: %s”, getValue.asStr());
int i = getValue.asInt();

if (i == 0)
{
digitalWrite(D6, HIGH);
}
else
{
digitalWrite(D6, LOW);
}
}
CAYENNE_IN(V7) //------------------- RELAY 3
{
CAYENNE_LOG(“Got a value: %s”, getValue.asStr());
int i = getValue.asInt();

if (i == 0)
{
digitalWrite(D7, HIGH);
}
else
{
digitalWrite(D7, LOW);
}
}
CAYENNE_IN(V8) //------------------- RELAY 4
{
CAYENNE_LOG(“Got a value: %s”, getValue.asStr());
int i = getValue.asInt();

if (i == 0)
{
digitalWrite(D8, HIGH);
}
else
{
digitalWrite(D8, LOW);
}
}


#2

Hi @marcx.han,

Have you tried connecting your ESP8266 device through our MQTT API with Add New > Device/Widget > MicroControllers > Generic ESP8266 yet? This is the officially supported way of connecting these devices to Cayenne that we’ve recently released. It would require a bit of code rewriting to conform to the way the MQTT API works (no virtualPins, data is passed on MQTT channels, and the virtualWrite() statements look a little different). But it may be worth trying the basic connection sketch there to see if it avoids the reset issue you’re having with this code.

That said, we have a lot of ESP8266 enthusiasts and experts on this forum who’ve connected and are using Cayenne via the Arduino method that you’re using here, and they may have a better idea than I about what you could change in this sketch to avoid this error message.


#3

Hi @rsiegel
thanks for your reply.
im using uno with wifi shield for my nodeMCU because i keep getting “error compiling for board nodeMCU 0.9 module.”

// 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[] = “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”;

unsigned long lastMillis = 0;

void setup() {
Serial.begin(9600);


#4

Could you show us the error you’re getting when attempting to compile that? There should be more detail in the Arduino IDE right under the message “error compiling for board nodeMCU 0.9 module.”


#5

Thanks @rsiegel
ok now i try MQTT method from another post and it works just fine for my boards without disconnecting problem and all my sensors working too :smile:


#6

Very cool. If you need any help interacting with specific sensor/actuators via MQTT you know where to find us. Glad to hear that you’re at least connected and running ok with the MQTT example.


#7

ah, now i got problem with my MQTT relay code now using my codes above, is there something wrong with my codes?
My relay keep on when device reboot so i need turn it of manualy on the app side.