Arduino ESP8266

I am trying to set up a Mozilla IoT Gateway-based system to measure the moisture content in a planting bed for automatic irrigation. I am using an Arduino Uno with an Adafruit Huzzah ESP8266. I have copied several examples of Arduino IDE code for the 8266 and have encountered compile errors. Example - using this code:

/**

  • Simple server compliant with Mozilla’s proposed WoT API
  • Originally based on the HelloServer example by Mozilla Wot.
  • Giovanni Gentile - projectj.it
  • aka masteruan
  • 25 January 2019
  • Tested on EPS8266-01 with relay modules.
  • You can buy the board by using: https://amzn.to/2B3hiWy
  • This Source Code is under CC BY-NC-SA 3.0
    */

#include <Arduino.h>
#include “Thing.h”
#include “WebThingAdapter.h”
#include <ESP8266WiFi.h>
#include “SoftwareSerial.h”

byte relON = {0xA0, 0x01, 0x01, 0xA2}; //Hex command to send to serial for open relay
byte relOFF = {0xA0, 0x01, 0x00, 0xA1}; //Hex command to send to serial for close relay

//TODO: Hardcode your wifi credentials here (and keep it private)
const char* ssid = “SSID”;
const char* password = “”;

WebThingAdapter* adapter;
SoftwareSerial esp8266(0,1);

const char* ledTypes = {“RelaySwitch”, “Light”, nullptr};
ThingDevice led(“relay”, “Relay-board”, ledTypes);
ThingProperty ledOn(“on”, “”, BOOLEAN, “OnOffProperty”);

bool lastOn = false;

void setup(void){

esp8266.begin(9600);

#if defined(ESP8266) || defined(ESP32)
WiFi.mode(WIFI_STA);
#endif
WiFi.begin(ssid, password);
//Serial.println("");

// Wait for connection
bool blink = true;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
adapter = new WebThingAdapter(“w26”, WiFi.localIP());

led.addProperty(&ledOn);
adapter->addDevice(&led);
adapter->begin();
}

void loop(void){
adapter->update();
bool acceso = ledOn.getValue().boolean;
if (acceso != lastOn) {
if (acceso) {
esp8266.write(relON, sizeof(relON));
delay(10);
esp8266.write(relON, sizeof(relON));
}
else{
esp8266.write(relOFF, sizeof(relOFF));
delay(10);
esp8266.write(relOFF, sizeof(relOFF));
}
}
lastOn = acceso;
}

I get the following error messages:

Arduino: 1.8.12 (Mac OS X), Board: “Adafruit Feather HUZZAH ESP8266, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

sketch_mar04c:27:23: error: ‘SoftwareSerial esp8266’ redeclared as different kind of symbol
SoftwareSerial esp8266(0,1);
^
In file included from /Users/rwpaar/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/Arduino.h:41:0,
from /Users/rwpaar/Documents/Arduino/sketch_mar04c/sketch_mar04c.ino:13:
/Users/rwpaar/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/core_esp8266_version.h:122:19: error: previous declaration of ‘namespace esp8266 { }’
namespace esp8266 {
^
/Users/rwpaar/Documents/Arduino/sketch_mar04c/sketch_mar04c.ino: In function ‘void setup()’:
sketch_mar04c:37:10: error: expected primary-expression before ‘.’ token
esp8266.begin(9600);
^
/Users/rwpaar/Documents/Arduino/sketch_mar04c/sketch_mar04c.ino: In function ‘void loop()’:
sketch_mar04c:62:14: error: expected primary-expression before ‘.’ token
esp8266.write(relON, sizeof(relON));
^
sketch_mar04c:64:14: error: expected primary-expression before ‘.’ token
esp8266.write(relON, sizeof(relON));
^
sketch_mar04c:67:14: error: expected primary-expression before ‘.’ token
esp8266.write(relOFF, sizeof(relOFF));
^
sketch_mar04c:69:14: error: expected primary-expression before ‘.’ token
esp8266.write(relOFF, sizeof(relOFF));
^
exit status 1
‘SoftwareSerial esp8266’ redeclared as different kind of symbol

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

Any suggestions?

Which Huzzah do you have?

For the Adafruit Feather HUZZAH with ESP8266 - Loose Headers : ID 2821 : $16.95 : Adafruit Industries, Unique & fun DIY electronics and kits , an Arduino Uno is redundant.

.

If you are set on using the Adafruit Feather HUZZAH with your Uno, you will need to change your software serial port name from esp8266 to something else that doesn't clash with predefined names from the core library. "esp8266" is not a very correct or descriptive name anyway.

I also recommend against using pin 1, since this pin is used for serial communication with the computer. If you use that pin for communication with the Uno, you will have problems if you want to print debug output from the ESP8266 to Serial Monitor and it also might cause uploads to fail.

Pin 0 is also problematic. This pin is used to activate the bootloader so you can upload sketches to the ESP8266. So using it for anything else might interfere with uploads. More information:

I grabbed this example as a starting point to try to get a handle on understanding the 8266 - I have tried multiple examples only to get error messages like 'SoftwareSerial esp8266' redeclared as different kind of symbol.

What does it mean? How do I get rid of it?

RWP396:
What does it mean?

It means the name "esp8266" has already been used. The error message shows you where the previous declaration was:

RWP396:

/Users/rwpaar/Library/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/cores/esp8266/core_esp8266_version.h:122:19: error: previous declaration of 'namespace esp8266 { }'

namespace esp8266 {

RWP396:
How do I get rid of it?

I already told you. Use a different name.

SoftwareSerial esp8266(0,1);

Probably fatal. These pins are for hardware serial.
Either put ESP on other pins, or use it with hardware serial. If the latter, you will need to disconnect it when uploading your programme.