ESP8266 and Arduino connected by SPI interface

Hi @JiriBilek

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");
}

Any sugestion?

Thanks a lot!
AS

Andrei,
try to simplify the setup function:

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.

Jiri

i used your library

but when i build in my IDE. had some prroblem

C:\Program Files (x86)\Arduino\libraries\wifi3/ESP8266WiFiGeneric.h:27:22: fatal error: functional: No such file or directory

#include functional

i can not include functianal

can you help me?

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.

How to install those library into Arduino IDE?

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.

Hi,

Thanks for your answer, it helps me a lot!
Now, i can see my device on thinger dashboard using Nano and NodeMCU.

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.

Is there any clue to solve this?

Hi, could you please post the relevant code?

Hi,

Here it is :

#define DEBUG
#define DISABLE_TLS

#include <WiFiSpi.h>
#include <ThingerWifiEspSpi.h>

//platform credentials
#define USERNAME “"
#define DEVICE_ID “**************”
#define DEVICE_CREDENTIAL "
******”

//gateway modem/router
#define SSID “******************”
#define SSID_PASSWORD “*********”

//Output definition
#define machine_on 5
#define machine_start 6

ThingerWifiEspSpi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
Serial.begin(9600);
Serial.println();
//Set output mode for all IO pins

pinMode(machine_on, OUTPUT);
pinMode(machine_start, OUTPUT);

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
}
};

thing[“Machine_Start”]<< digitalPin(6);

}

void loop() {
thing.handle();
}

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.

Hi,
The output of “machine start” is also low (around 0V) when i press the button on thinger dashboard.

Hi, you really need to make a debug output. As I wrote you in my previous post, make sure you are getting correct values in the in variable. You have to add some Serial.print() in your function.

Hi,

After adding Serial.println() before “else” statement, this is the debug output when i press the button on thinger dashboard :

[_SOCKET] Connecting to [my_server_domain]
[_SOCKET] Using secure TLS/SSL connection: no
[_SOCKET] Connected!
[THINGER] Authenticating. User: ****** Device: ********
[THINGER] Writing bytes: 52 [OK]
[THINGER] Authenticated
[THINGER] Available bytes: 25
[THINGER] Writing bytes: 8 [OK]

[THINGER] Writing bytes: 15 [OK]
[THINGER] Available bytes: 86
[THINGER] Writing bytes: 8 [OK]
[THINGER] Available bytes: 58
[THINGER] Writing bytes: 7 [OK]
[THINGER] Available bytes: 30
[THINGER] Writing bytes: 8 [OK]
[THINGER] Available bytes: 19
[THINGER] Writing bytes: 4 [OK]

[THINGER] Writing bytes: 15 [OK]
[THINGER] Available bytes: 19
[THINGER] Writing bytes: 4 [OK]

[THINGER] Writing bytes: 15 [OK]
[THINGER] Available bytes: 19
[THINGER] Writing bytes: 4 [OK]

[THINGER] Writing bytes: 15 [OK]
[THINGER] Available bytes: 19
[THINGER] Writing bytes: 4 [OK]

[THINGER] Writing bytes: 15 [OK]
[THINGER] Available bytes: 19
[THINGER] Writing bytes: 4 [OK]

[THINGER] Writing bytes: 15 [OK]
[THINGER] Available bytes: 19
[THINGER] Writing bytes: 4 [OK]

FYI, i am using my own VPS for the platform.

First, when you add debug printouts, you have to print something unique and useful, not only newline. Any unique text would do.
Second, if the newlines got printed out after you pressed the button and the app should have run the else statement, then something is wrong. Maybe the variable in is always empty. You definitely have to find this out via another debug printout.

Actually, there is exactly same result for the code of “thing[“Machine_Start”]<< digitalPin(6);”.
That code is straight to the point for boolean On & Off.
Another hardware that i am using is only NodeMCU for both main controller & wifi controller, and also executing the same function like this :

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
}
};

The result is good, output pin is high for 100ms then going low. Works perfect.
My point is, there is nothing wrong with “in” variable, because another hardware that have direct connection to WiFi prove that this is okay.

Hi @Andrei_Sousa,

What is the progress of this experiment? Did you experience any strange result using WiFiEspIsp?

hi @jiriBilek , using this library for wemos d1 mini pro as wifi module for a teensy4, does it suport udp data transmission , if so any exmples availalble? i want to stream udp in broadcast mode as fast as possible. this is a great little library much much better than the serial at commands !!! regards
phil.

Hi @philw.
On my github you can find and example how to read current time and date from NTP server. This is a UDP communication.


Jiri

yes i saw the code in WiFiSPICmdUdp.cpp a while after i posted!! thanks ill check it out , i also need to start the wifi in accesspoint mode if the supplied ssid is not found. i cant see any equivalent of wifi.beginAp , i was considering adding something to WiFiSPICmdGeneral.cpp
been programming 35 years started in C but not used ot for years and only recently got back into C++. I like your style nic set of routines good structure.