[Arduino Uno + ESP8266 13] Can turn on an LED, but not able to turn off / receive data

Hello,

I am using my Arduino Uno and the [awful] duinotech 8266 wifi shield ESP 13. Awful in that it has taken a good year or so to wrap my head around what the hell it is doing. Flashing firmware, AT commands, with it’s minimal documentation. I eventually had success using this guide. Note that the ESP 13 is a board / shield itself.

I have been able to connect to Cayenne, and add my device to the dashboard using MQTT. There is a bit of dropping in and out with the connection. I added an Led, added the bit of code needed, and then added the button widget to my dashboard.

When I click the button, the Led on my board lights up as it should. But, then the button icon on the dashboard does not reflect that the state of the Led has changed, and, on the dashboard, continues to show the loading circle. Clicking the button again while it is in this state does not turn off the Led.

Refreshing the page usually causes the board to lose connectivity, or for the button on the dashboard to be in the off state while the physical Led is on.

I suspect that no data is being received from my Arduino. And that Cayenne is waiting to receive a response state to then update the state of the dashboard.

This is supported by when even using the millis example, given within the example code, no widget is “automatically added to the dashboard” to show up time. And when I manually add a counter to receive the uptime over a predefined virtual channel, the counter does not update.

Can anyone help me with this problem?

/*
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 "SoftwareSerial.h"


// WiFi network info.
char ssid[] = "curseduinotech";
char wifiPassword[] = "throwitinthebin";

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

#define ledpin 13

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
SoftwareSerial Serial1(2, 3); // RX, TX
#define EspSerial Serial1

ESP8266 wifi(&EspSerial);

void setup()
{
	Serial.begin(115200);
	delay(10);

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

	Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
  pinMode(ledpin, OUTPUT);
}

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

CAYENNE_IN(1)
{
  digitalWrite(ledpin, getValue.asInt());
}

CAYENNE_OUT(0)
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
}

If you uncomment #define CAYENNE_DEBUG do you see any errors in your serial console?

Hi Adam, thanks for your time.

No errors here.

[55952] Connected to WiFi
[55952] Connecting to mqtt.mydevices.com:1883
[58579] Connected
[59942] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key
[64970] Publish: topic 6, channel 65534, value ATmega328P, subkey , key
[69999] Publish: topic 7, channel 65534, value 16000000, subkey , key
[75028] Publish: topic 5, channel 65534, value 1.2.0, subkey , key
[80057] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key
[80118] Publish: topic 1, channel 0, value 80118, subkey , key
[90107] Connection ok
[95136] Publish: topic 1, channel 0, value 95136, subkey , key
[100118] Connection ok
[110148] Publish: topic 1, channel 0, value 110148, subkey , key
[111620] Connection ok
[121630] Connection ok
[125154] Publish: topic 1, channel 0, value 125154, subkey , key
[131642] Connection ok
[140165] Publish: topic 1, channel 0, value 140165, subkey , key
[141655] Connection ok
[151685] Connection ok
[155179] Publish: topic 1, channel 0, value 155179, subkey , key
[161686] Connection ok

On clicking Led button on dashboard. Led lights up within 2 seconds.

[236318] Connection ok
[245026] Message received: topic 2, channel 1
[245027] In: value 1, channel 1
[245028] publishState: topic 1 channel 1
[245031] Publish: topic 1, channel 1, value 1, subkey , key
[250065] Send response: y3tI0tIJo6qKwtI
[255093] Publish: topic 1, channel 0, value 255093, subkey , key
[260121] Connection ok

Dashboard button not changing it’s state, but still in a pending state
2018-09-03_12h36_31

@shramik_salgaonkar any ideas? Looks ok to me.

try connecting the shield manually to Rx and Tx of arduino and use Serial for communication between shield and Uno. Next comment out all serial print command and dont use Serial for debugging.

1 Like

Fantastic!

I can now turn off my LED! And when I check the live data feed I am getting the milliS uptime.

You may hear from me again, but thank you to both of you.