B4R Question ESP8266 WiFi shield on UNO

bdunkleysmith

Active Member
Licensed User
Longtime User
I've a fully functioning Arduino project which collects data and sends it to a PC in serial form via USB for processing by a B4J app. I want to move from a wired (USB) to a wireless (WiFi) connection. Should be simple I thought. So to do that I added an ESP8266 based WiFi (DuinoTECH ESP13) shield to my DuinoTECH Classic (UNO).

As per ESP8266 - Getting Started in the Arduino IDE - File - Preferences I have added the URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json to the Additional Boards Manager URLs field and in Arduino IDE - Tools - Board - Boards Manager installed esp8266 by ESP8266 community.

Now I want to use the ESP8266 as a shield on the UNO rather than as a standalone board because I already have interface hardware and code to collect the data. I just want the ESP8266 shield to send the serial data collected by the UNO as UDP packets via WiFi. I have already updated by B4J client code to receive the data either via USB or UDP.

To test that I can send UDP packets I tried the following simple code:

B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private Timer1 As Timer
    Private usocket As WiFiUDP
    Private wifi As ESP8266WiFi
    Private ip() As Byte = Array As Byte(192, 168, 0, 255)
    Private port As UInt = 3661
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
 
    If wifi.Connect2("Telstra1943", "********") = False Then
        Log("Error connecting to network")
        Return
    Else
        Log("Connected to network")
    End If
    usocket.Initialize(51042, "usocket_PacketArrived")
    Timer1.Initialize("Timer1_Tick", 500)
    Timer1.Enabled = True
 
End Sub


Private Sub Timer1_Tick
    usocket.BeginPacket(ip, port)
    usocket.Write("T 9:35")
    usocket.SendPacket
End Sub

Private Sub usocket_PacketArrived (Data() As Byte, ip1() As Byte, port1 As UInt)
    'not used
    Log("Packet arrived")
End Sub

In B4R I selected the UNO board, however on compiling the code I receive the following fatal error:

B4X:
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Bryon\AppData\Local\Arduino15\packages -hardware C:\Users\Public\Documents\Bryon\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Bryon\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Public\Documents\Bryon\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10802 -build-path C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin -warnings=all -build-cache C:\Users\Bryon\AppData\Local\Temp\arduino_cache_252351 -prefs=build.path=C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2 -prefs=runtime.tools.avrdude.path=C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.1.1 -verbose C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\src\src.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Bryon\AppData\Local\Arduino15\packages -hardware C:\Users\Public\Documents\Bryon\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Bryon\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Public\Documents\Bryon\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10802 -build-path C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin -warnings=all -build-cache C:\Users\Bryon\AppData\Local\Temp\arduino_cache_252351 -prefs=build.path=C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2 -prefs=runtime.tools.avrdude.path=C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9 -prefs=runtime.tools.arduinoOTA.path=C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.1.1 -verbose C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\src\src.ino
Using board 'uno' from platform in folder: C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20
Using core 'arduino' from platform in folder: C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20
Detecting libraries used...
"C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino" "-IC:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\variants\standard" "C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin\sketch\src.ino.cpp" -o "nul"
"C:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino" "-IC:\Users\Bryon\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\variants\standard" "C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin\sketch\src.ino.cpp" -o "C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin\preproc\ctags_target_for_gcc_minus_e.cpp"
In file included from C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin\sketch\B4RDefines.h:27:0,
                 from C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\src\src.ino:1:
C:\Users\Public\DOCUME~1\Bryon\Arduino\Weather\Objects\bin\sketch\rESP8266WiFi.h:7:25: fatal error: ESP8266WiFi.h: No such file or directory
#include <ESP8266WiFi.h>
                         ^
compilation terminated.
exit status 1

While it says "
ESP8266WiFi.h: No such file or directory" ESP8266WiFi.h is at least in C:\Users\Bryon\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src but should it also be elsewhere so it can be found?

Or have I misunderstood how a shield works and in fact I can't load code based on the ESP8266 libraries onto the UNO and this is only possible by loading the code directly onto the ESP8266 based WiFi shield?

I thought given I already had a fully functioning Arduino data gathering hardware/software combination which output the serial data via USB that it would be a simple matter to add a WiFi shield and have that data sent via UDP over WiFi. I did achieve some basic functionality by using ESP8266 AT commands, but I could see limitations with that which I thought would be overcome by using features within the ESP8266 libraries.

I normally pick these things up reasonably quickly, but I seem to be struggling with the concept of shields on Arduino boards. Any pointers in the right direction would be appreciated.
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Erel I respect your responses and I'm awaiting delivery in the next day or so of a FDTI USB board so I can program the ESP8266 directly. But I was guided by this user manual which is for a shield which looks identical to mine.

With the WiFi shield connected to the Uno, but with the DIP switches set to off so the WiFi shield serial port is not connected to the Uno, they show loading the wifiTest example (attached) with the Arduino Uno on Com10 in the Arduino IDE and it shows no compilation errors. However when I do that I get:

C:\Users\Public\Documents\Bryon\Arduino\wifiTest\wifiTest.ino:54:22: fatal error: uartWIFI.h: No such file or directory

So given I get the same "No such file or directory" error, but for ESP8266WiFi.h when I use B4R to upload the test project, I just wonder if I have a file or directory path/location problem.
 

Attachments

  • wifiTest.ino.txt
    1.8 KB · Views: 372
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks Erel and derez for your guidance.

It is now clear to me that the architecture of compiling code separately for the UNO and ESP and just having them exchange data is the way to go. It also has the benefit that my existing fully functioning Arduino hardware/software can remain basically as is. I just have to code the ESP to consume the serial data and send it via WiFi.

But I'm still confused as to why the example from the User Manual doesn't work. I can only presume the example is no longer valid due to changes in firmware, libraries or something else since the manual was written.

I now need to put that lingering question out of my mind and concentrate on coding the ESP directly and I'll report the results back here in case it is of use to others working with this hardware.

Incidentally I was looking to use softserial as a means on inputting configuration data via a USB keyboard, eg. password for access point selected from a list created from scanning APs, which a user will have to do each time the application is launched. I presume there is nothing fundamentally flawed in that concept.
 
Upvote 0
Top