WifiShield with arduino uno compiling error

Try this:

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "AuthenticationToken";
// Your network name and password.
char ssid[] = "NetworkSSID";
char password[] = "NetworkPassword";

void setup()
{
	Serial.begin(9600);
	Cayenne.begin(token, ssid, password);
}

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

it shows this errors:
In file included from arduino_IOT.ino:47:
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h:15:2: error: #error This code is intended to run on the ESP8266 platform! Please check your Tools->Board setting.
In file included from arduino_IOT.ino:47:
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h: In member function ‘void BlynkWifi::connectWiFi(const char*, const char*)’:
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h:39: error: ‘WiFi’ was not declared in this scope
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h:39: error: ‘WIFI_STA’ was not declared in this scope
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h:45: error: ‘WL_CONNECTED’ was not declared in this scope
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h: At global scope:
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h:92: error: ‘WiFiClient’ does not name a type
C:\Users\dhafer\Documents\Arduino\libraries\Cayenne/BlynkSimpleEsp8266.h:93: error: ‘_blynkWifiClient’ was not declared in this scope

If you click the Tools menu, next to Board, is there an ESP device listed there? If not hover over Board and select whichever variant you are using.

I DONT find it. But the problem appear when i made the compilation(when i cliked in the buton colored in yellow in the picture below) , not when i downloded the code in the board.

Do you have the ESP boards installed?

Installing with Boards Manager

Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32 and 64 bit).

Install Arduino 1.6.8 from the Arduino website.
Start Arduino and open Preferences window.
Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
Open Boards Manager from Tools > Board menu and install esp8266 platform (and don’t forget to select your ESP8266 board from Tools > Board menu after installation).

If you are using the ESP8266 as a Wifi shield with the AT command set installed on the ESP, and the Uno as the host, then this will not work.

@adam is talking about overwriting the flash in the ESP module itself so you don’t even need an Uno.

Connect your Uno serial port RX to TX and TX to RX on the ESP. Note that the ESP pins are 5V tolerant, but if you want to be nice, put a 1K resistor inline between the Uno TX and the ESP RX. Also note that the ESP supply must be 3.3V. If you put 5V there, it will get hot.

You need this code if using the ESP as a shield (unreleased code):

/*
Cayenne ESP8266 Shield WiFi Example
Adapted from Blynk's ESP8266_Shield_HardSer Example

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

You should install the ESP8266HardwareSerial.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library)
from the Cayenne extras/libraries folder (e.g. My Documents\Arduino\libraries\Cayenne\extras\libraries) to compile this example.

NOTE: Ensure a stable serial connection to ESP8266!
      Firmware version 1.0.0 (AT v0.22) or later is needed.
      You can change ESP baud rate. Connect to AT console and call:
          AT+UART_DEF=115200,8,1,0,0

For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Channels, data
should be sent to those channels using virtualWrites. Examples for sending and receiving
Virtual Channel data are under the Basics folder.
*/

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneESP8266Shield.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "AuthenticationToken";
// Your network name and password.
char ssid[] = "NetworkSSID";
char password[] = "NetworkPassword";

// Set ESP8266 Serial object
#define EspSerial Serial1
ESP8266 wifi(EspSerial);

void setup()
{
	Serial.begin(9600);
	delay(10);
	// Set ESP8266 baud rate

	EspSerial.begin(115200);
	delay(10);

	Cayenne.begin(token, wifi, ssid, password);
}

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

This code relies on your Arduino device having a second serial port. You will need to install the attached CayenneESP8266Shield.log to your Cayenne library directory and rename it with a .h extension. Also, don’t forget to install the ESP8266HardwareSerial library (rename attached as .zip)

I am working on kludging a way to use the SoftwareSerial library as well, but haven’t got around to it yet.

CayenneESP8266Shield.log (1.8 KB)

ESP8266HardwareSerial.log (11.3 KB)

Cheers,

Craig

2 Likes

lol not sure how I missed that. Selective reading I guess…

I’m just here to keep an eye on you, Adam :stuck_out_tongue:

Cheers,

Kreggly returns to designing his IoT flamethrower.

Hello Kreggly

I am new to Cayenne community was trying to connect Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.

I found above information helpful, as per your suggestion tried to compile above code in Arduino IDE, but getting below error .

C:\Users\hp\Documents\Arduino\sketch_dec10a\sketch_dec10a.ino:24:34: fatal error: CayenneESP8266Shield.h: No such file or directory compilation terminated.

I don’t have “ESP8266HardwareSerial.zip” library in my Cayenne extras/libraries folder (e.g. My Documents\Arduino\libraries\Cayenne\extras\libraries)

Requesting you please share this zip file .

Best Regards
Prashant

I have pro with this, can you help me ???

Cayenne/BlynkSimpleShieldEsp8266_HardSer.h:27:29: fatal error: ESP8266_HardSer.h: No such file or directory

** #include ESP8266_HardSer.h**

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

@ehkrap and @ngovan.thanh,

You need to look up and copy the CayenneESP8266Shield.log file into the Cayenne directory and rename it with the .h extension. Then take ESP8266HardwareSerial.log and rename it with the .zip extension and install it via the Arduino IDE (Sketch->Include Library->Add .ZIP Library)

There is no official release of the ESP shield code for Cayenne yet, so we have to do it this way.

Cheers,

Craig

Thanks you so much, I’ll try to do it

I tried this, but received errors opening the library .zip:

Arduino: 1.6.13 (Windows 7), Board: “ESPDuino (ESP-13 Module), 80 MHz, 115200, 4M (3M SPIFFS)”

java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(ZipFile.java:219)
at java.util.zip.ZipFile.(ZipFile.java:149)
at java.util.zip.ZipFile.(ZipFile.java:163)
at processing.app.tools.ZipDeflater.(ZipDeflater.java:26)
at processing.app.Base.handleAddLibrary(Base.java:2206)
at processing.app.Base$6.actionPerformed(Base.java:1032)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Looks like you have a privilege issue on your PC. Try running the Arduino IDE as administrator.

You can also unzip the library and copy the folder into the libraries directory, then restart the IDE.

Cheers,

Craig

My bad - forgot I was using Windows (I needed Win7 for something else) and saved the file incorrectly instead of renaming it.

Sorry, I am new to this and should probably go back to easier stuff until I get my head around it - I get this now:

Arduino: 1.6.13 (Windows 7), Board: “ESPDuino (ESP-13 Module), 80 MHz, 115200, 4M (3M SPIFFS)”

C:\Users\tbscully\Documents\Arduino\libraries\Cayenne\ESP8266.cpp:22:26: fatal error: avr/pgmspace.h: No such file or directory

#include <avr/pgmspace.h>

                      ^

compilation terminated.

exit status 1
Error compiling for board ESPDuino (ESP-13 Module).

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Hmmmm, this is a new one to me. I think it is because it is not actually an ESP8266, thus the libraries aren’t recognizing it correctly and trying to do AVR things that aren’t compatible as the ESPs are not AVR based.

You could try removing the ESP8266 board from the boards manager, and use the additional boards json from the following link to install perhaps an updated version that includes this board. https://www.tindie.com/products/doit/espduinowifi-arduino-uno-r3/

UPDATE: I looked at the link and yes, they replaced the Generic ESP8266 Module in the file with the ESPDuino. I don’t recommend doing the above as they are using an old version. Just try setting it to Generic ESP module and see if it compiles for you.

@bestes, does anyone at “home office” have one of these boards?

Cheers,

Craig

Hello Kreggly!

I´m trying to do your example.
I use a Arduino UNO + ESP8266-01.
I done exactly what you said, but I have some issue with the serial between UNO and the ESP.
With the code you post, I will have the error: “‘Serial1’ was not declared in this scope”

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneESP8266Shield.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "*****";
// Your network name and password.
char ssid[] = "*****";
char password[] = "*****";

// Set ESP8266 Serial object
#define EspSerial Serial1
ESP8266 wifi(EspSerial);

void setup()
{ .......

I also install the library ESP8266HardwareSerial.zip like you said, I got 3 files “ESP8266.cpp”, “ESP8266_HardSer.h” and the “README.md”. But I´m not sure how I should use it… maybe I miss some detail!
Where I define the rx and tx pins to serial between UNO + ESP?

Thanks a lot!
AS

Hi @andreijrs,

You don’t have a separate serial port on the UNO, so you need to disable the debug port and use Serial to connect to the ESP shield. You don’t need to define pins as it is knows them already. They are the ones labelled RX and TX on the board. Just note when programming that you disconnect the ESP from the UNO so there are no confilcts, then reconnect after programming.

You can try adding a second serial port with the software serial library if you want to keep debug, but note that the UNO doesn’t have much program space if you plan on adding more user code.

See here:

/*
Cayenne ESP8266 Shield WiFi Example
Adapted from Blynk's ESP8266_Shield_HardSer Example

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

You should install the ESP8266HardwareSerial.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library)
from the Cayenne extras/libraries folder (e.g. My Documents\Arduino\libraries\Cayenne\extras\libraries) to compile this example.

NOTE: Ensure a stable serial connection to ESP8266!
      Firmware version 1.0.0 (AT v0.22) or later is needed.
      You can change ESP baud rate. Connect to AT console and call:
          AT+UART_DEF=115200,8,1,0,0

For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Channels, data
should be sent to those channels using virtualWrites. Examples for sending and receiving
Virtual Channel data are under the Basics folder.
*/

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneESP8266Shield.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "";
char ssid[] = "";
char password[] = "";


// Set ESP8266 Serial object
#define EspSerial Serial
ESP8266 wifi(EspSerial);

void setup()
{
	//Serial.begin(9600);
	delay(10);
	// Set ESP8266 baud rate
	EspSerial.begin(115200);
	delay(10);

	Cayenne.begin(token, wifi, ssid, password);
}

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

Cheers,

Craig

Hi @kreggly!
Thanks for your help.
At this moment I want a second serial port for debug, my code is something like:

#include <CayenneESP8266Shield.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "***";
// Your network name and password.
char ssid[] = "***";
char password[] = "***";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(7, 8); // RX, TX

// Set ESP8266 Serial object
ESP8266 wifi(EspSerial);

void setup() {...

Why I still have an error here?!

ESP8266 wifi(EspSerial);

“no matching function for call to ‘ESP8266::ESP8266(SoftwareSerial&)’”

Can you please help?

Thanks you!

@andreijrs,

Looks like the ESP8266 library has no handler for SoftwareSerial.

Craig