Hi,
I have just uploaded two projects to github that in my oppinion solve the problem with using ESP8266 modules as slaves to Arduino MCUs.
Instead of the serial interface the SPI interface is used here. Therefore the ESP module must be reflashed to a custom firmware.
The WiFiSpiESP project is in fact an application and must be flashed to ESP module while the WiFiSpi project is an Arduino library. I tried to keep the library objects and functions as close as possible in its behaviour to the default Arduino’s WiFi library in order to make migration to the WiFiSpi library easy.
I know that flashing ESP module may not be a solution for beginners, but I am afraid there is no chance to make a robust solution on AT command protocol and SoftwareSerial class.
Hi @JiriBilek
This is great! Only today I saw this.
I will try it, I hope in the next days.
If I understand well I need to flash SPI Slave for ESP8266 module and use the SPI library for Arduino AVR to connect with ESP8266, it seems easy
I will give a feedback for sure.
Thanks!
#include <WiFiSpi.h>
#include <ThingerWifi.h>
#define username "****"
#define deviceId "****"
#define deviceCredential "****"
#define ssid "****"
#define pass "****"
//int status = WL_IDLE_STATUS; //I´m not sure if I need this here
ThingerWifi thing("username", "deviceId", "deviceCredential"); // I get an error here
WiFiSpiClient client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// Initialize the WifiSpi library
WiFiSpi.init();
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
String fv = WiFiSpi.firmwareVersion();
if (fv != "0.1.0") {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFiSpi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
// configure wifi network
thing.add_wifi(ssid, pass);
pinMode(5, OUTPUT);
// pin control example (i.e. turning on/off a light, a relay, etc)
thing["led"] << digitalPin(5);
// resource output example (i.e. reading a sensor value, a variable, etc)
thing["millis"] >> outputValue(millis());
// more details at http://docs.thinger.io/arduino/
}
void loop() {
thing.handle();
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFiSpi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFiSpi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFiSpi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
I need to change in “ThingerWifi.h” where is “WiFi” to “WiFiSpi”?
The error is: C:\Users\admin\Documents\Arduino\libraries\Arduino-Library-master\src/ThingerWifi.h:46:17: error: 'WiFi' was not declared in this scope
I need your help to make the first example.
Thanks!
AS
Hi @JiriBilek!
I was doing several errors in the example I sent before.
First I need include the file ThingerESP8266AT.h and now I have a difrent error: ThingerESP8266AT.h:64:5: error: 'TinyGsm' does not name a type
Now I can do the upload to the Arduino with no errors.
But for some reason the STATE of the device is always Disconnected, I don´t understand what I´m doing wrong.
The issue is in the code I upload?
The code I upload now is:
#include <WiFiSpi.h>
#include <ThingerWifiEspSpi.h>
#define username "***"
#define deviceId "***"
#define deviceCredential "***"
#define ssid "***"
#define pass "***"
int status = WL_IDLE_STATUS;
ThingerWifiEspSpi thing("username", "deviceId", "deviceCredential");
WiFiSpiClient client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// Initialize the WifiSpi library
WiFiSpi.init();
// check for the presence of the shield
if (WiFiSpi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
String fv = WiFiSpi.firmwareVersion();
if (fv != "0.1.0") {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFiSpi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
// configure wifi network
thing.add_wifi(ssid, pass);
pinMode(5, OUTPUT);
// pin control example (i.e. turning on/off a light, a relay, etc)
thing["led"] << digitalPin(5);
// resource output example (i.e. reading a sensor value, a variable, etc)
thing["millis"] >> outputValue(millis());
// more details at http://docs.thinger.io/arduino/
}
void loop() {
thing.handle();
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFiSpi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFiSpi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFiSpi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// Initialize the WifiSpi library
WiFiSpi.init();
// check for the presence of the shield
if (WiFiSpi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
String fv = WiFiSpi.firmwareVersion();
if (fv != "0.1.0") {
Serial.println("Please upgrade the firmware");
}
// configure wifi network
thing.add_wifi(ssid, pass);
... etc. etc. ...
Don’t connect the wifi manually, let thinger do the work. If it doesn’t help, connect serial monitor to ESP and look at the output. The serial output from Arduino may help, too.
Hi,
what library are to refering to? The one for Arduino or are you trying to compile the part for ESP8266?
I tried to find the ESP8266WiFiGeneric.h file on my computer and I didn’t find it. So could it be you have more wifi libraries installed and the error comes from another library?
Hi @JiriBilek
I’ve tried using your library to connect between NodeMCU and Arduino Nano. When i installs the WifiSpi for arduino, it is straight forward by adding Zip library on Arduino IDE. But when i tried to installs WifiIspEsp using same method, it show error : Specified folder/zip file does not contain a valid library.
I also tried manual install for WifiIspEsp, unzip the folder, and copy all of the file into library folder of arduino. And still got same error message.
Hi @astonix ,
the ESP part is not a library. It is an application instead. You must load ESP8266 toolchain into arduino, see https://github.com/esp8266/Arduino. Then open the .ino file, compile it and load it into the MCU.
Hello @JiriBilek,
I’ve been using your library for analog monitoring and the result is good, the thingerio dashboard is showing measurement data as expected. But, when i tried to use GPIO control over dashboard, there is no action on output. I already measure the output voltage pin when i press the button on dashboard and it is still 0V. It should be around 3,3V - 5V.
I am using ATmega328 (Nano) as main controller, and NodeMCU (ESP8266) as wifi controller.
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// Initialize the WifiSpi library
WiFiSpi.init();
delay(10);
thing.add_wifi(SSID, SSID_PASSWORD);
thing[“Machine_On”]<< (pson& in) {
if(in.is_empty()){
in=(bool)digitalRead(5);
}else{
digitalWrite(5, in ? LOW : HIGH); //Here is the control of the GPIO5
digitalWrite(machine_on, HIGH); // Get start
delay(100); // sending delay 100ms
digitalWrite(machine_on, LOW); // Get low
}
};
As I understand, the problem is in not entering the “else” part of the “Machine_On” function. Just to be sure, place please a Serial.print there and print the in variable value. Maybe the in variable is always empty.