I have some code that runs on an ESP-32 just fine. It listens for what is basically a 38400 baud ASCII stream of data arriving on one pin, splits it into pieces that make sense (they are NMEA sentences or AIS sentences for a marine application) and sends them out as wifi packets. This works fine.
I'm hoping to adjust it slightly (mostly getting rid of some stuff that drives an unnecessary display that I used for debugging) and get it to run on an ESP01.
I'm programming the ESP-01 using an ESP-12 module in a kind of pass-through mode (as described here); I've gotten a blink sketch to work, so I know that the programming part is working OK. The downside of this programming method is that I have to select NodeMCU-1.0 in the "tools" menu, and that means that all the "defines" for pins are messed up, but I can live with that.
As a next step, since "blink" compiles and runs, I tried just grabbing my code, changing a #define to #undef to get rid of all references to the display, and compiling...and I got a jackpot of errors, all related to the WiFi library. I assume that I've got something messed up in my library inclusions, etc.
A few possibly-relevant details: I'm on a Mac; using Arduino 1.8.7. I've got WiFi Built-In 1.2.7 installed.
Here's the first bit of the code, with most comments removed -- (the rest is in an attachment if you're a glutton for punishment)--- and then the first few errors generated by compiling it (with target "NodeMCU 1.0 (ESP-12E module)"); the remaining errors are all of a similar flavor.
I'd sure appreciate it if anyone can suggest what's going on here, and how I might make this work.
--John
#include <WiFi.h>
#include <WiFiUdp.h>
#include <HardwareSerial.h>
#include <pins_arduino.h>
// WiFi setup -------------------------------
const char* ssid = "DCFBoat2"; // My network data; yours may vary
const char* pass = "Prudence"; //
IPAddress ipBroadcast(192, 168, 1, 255);
// The not-quite standardized port for transmitting NMEA data over IP.
#define NMEA_PORT 10110
unsigned int portBroadcast = NMEA_PORT;
WiFiUDP Udp; // An instance of the WiFi UDP class that can send and receive UDP messages.
#define ALARM_PIN 23
unsigned long alarmStart = 0;
bool alarmOn = false;
#define GX2200_NMEA_SPEED 38400
#define MONITOR_BAUD_RATE 57600
HardwareSerial NMEASerial(1);
#define BLOCK_SIZE 20
#define SERIAL_BUFFER_SIZE 1024
byte espABuffer[SERIAL_BUFFER_SIZE]; // The data we've read from the ESP's serial buffer
int bufferAStart = 0; // where the un-processed data starts; generally espABuffer[bufferAStart] is the next character for us to work on.
int bufferAEnd = 0; // The end of the un-processed data: the byte at espABuffer[bufferAEnd] is meaningless. Note that if bufferAStart == bufferAEnd, then the buffer contains no unprocessed data.
byte sentenceA[128]; // The sentence we're currently assembling
int sentenceALength = 0; // How many characters are in this sentence so far
boolean inSentenceA = false; // Have we in fact started accumulating data for a sentence (i.e., have we seen the
// appropriate starting character, either '
And here is the start of the errors generated when I try to compile that code (there are lots more, but they all look very similar).
In file included from /Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:32:0,
from /Users/jfh/Desktop/HOBBY/ESP-NMEA/VHF2Wifi/GPS2WIFI-B-1/GPS2WIFI-B-1.ino:10:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFiServer.h:37:14: error: invalid abstract return type for member function 'WiFiClient WiFiServer::available(uint8_t*)'
WiFiClient available(uint8_t* status = NULL);
^
In file included from /Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:31:0,
from /Users/jfh/Desktop/HOBBY/ESP-NMEA/VHF2Wifi/GPS2WIFI-B-1/GPS2WIFI-B-1.ino:10:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFiClient.h:27:7: note: because the following virtual functions are pure within 'WiFiClient':
class WiFiClient : public Client {
^
In file included from /Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFiClient.h:24:0,
from /Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:31,
from /Users/jfh/Desktop/HOBBY/ESP-NMEA/VHF2Wifi/GPS2WIFI-B-1/GPS2WIFI-B-1.ino:10:
/Users/jfh/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.0-beta2/cores/esp8266/Client.h:29:21: note: virtual int Client::connect(const IPAddress&, uint16_t)
virtual int connect(CONST IPAddress& ip, uint16_t port) =0;
^
/Users/jfh/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.0-beta2/cores/esp8266/Client.h:37:22: note: virtual bool Client::flush(unsigned int)
virtual bool flush(unsigned int maxWaitMs = 0) = 0;
^
/Users/jfh/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.0-beta2/cores/esp8266/Client.h:38:22: note: virtual bool Client::stop(unsigned int)
virtual bool stop(unsigned int maxWaitMs = 0) = 0;
^
GPS2WIFI-B-1:33:9: error: cannot declare variable 'Udp' to be of abstract type 'WiFiUDP'
WiFiUDP Udp; // An instance of the WiFi UDP class that can send and receive UDP messages.
^
GPS2WIFI-B-1.ino (13.3 KB) or '!', but not yet finished the sentence with a 'n' character?
// Forward declarations for helper procs
void setupWiFi();
void flashAlarm();
void lightOn();
void lightOff();
void sendUDP(const byte packet[],int packetSize);
void resetSentence(byte sentence[], int& len, boolean& sentenceFlag);
void processInput(byte bufferData[], int& bufferStart, int& bufferEnd, byte sentence[], int& sentenceLength, boolean& inSentence);
void alarmCheck();
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); //
pinMode(ALARM_PIN, OUTPUT);
digitalWrite(ALARM_PIN, LOW);
lightOn();
flashAlarm();
delay(50);
lightOff();
delay(50);
lightOn();
delay(1000);
lightOff();
alarmCheck();
NMEASerial.begin(GX2200_NMEA_SPEED, SERIAL_8N1, 25, 14);
Serial.begin(MONITOR_BAUD_RATE);
Serial.println("Working...");
setupWiFi();
Serial.println("Done with IP setup.");
delay(300);
Serial.flush();
}
void loop()
{
alarmCheck(); // check to see whether it's time to reset the alarm LED
// Check and handle data on each serial line.
dataCheck(NMEASerial, espABuffer, SERIAL_BUFFER_SIZE, bufferAStart, bufferAEnd, inSentenceA, sentenceALength, sentenceA);
Serial.print(bufferAEnd);
Serial.print(": ");
String s = (char *) espABuffer;
Serial.println(s);
}
And here is the start of the errors generated when I try to compile that code (there are lots more, but they all look very similar).
§DISCOURSE_HOISTED_CODE_1§
[GPS2WIFI-B-1.ino|attachment](upload://rSTXKyZUnjOfBzSYBNIAKUHsPcz.ino) (13.3 KB)