I have successfully built a SparkFun project using an Arduino mini and a ESP8266 NodeMCU 12-E. I teach a robotics high school course (I do not have a degree in programming or engineering so I have learned this on my own). I would like to introduce them to some IoT concepts using this board. We will be using an AP not connected to the internet in order to run a Blynk local server. The students will connect their phones to the server and their projects using the ESP 8266 modules.
To get them started I would just like to show them how to control an LED with the app. I am having some difficulty connecting the ESP 8266 to the server. I can see my laptop, phone and the raspberry pi which is running the Blynk server all connected on the router's console but the wifi module does not seem to connect. I have checked the credentials in the sketch and the app token. They all seem to be correct. For these projects they will be using the ESP8266 modules with Arduino UNOs.
Perhaps there is something I am missing. Here is the sketch I am trying to run which will not connect:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "0b22c504b7534e4e87732e2f75529926";
// WiFi credentials.
char ssid[] = "MechLab-2.4GHz";
char pass[] = "myPass";
int pinV0;
int redLED = 13;
void setup() {
Blynk.begin(auth, ssid, pass);
pinMode (redLED, OUTPUT);
}
void loop() {
Blynk.run();
if (pinV0 == 1){
digitalWrite(redLED, HIGH);
}
else {
digitalWrite(redLED, LOW);
}
}
BLYNK_WRITE(V0){
pinV0 = param.asInt(); // assigns incoming value button to pinV0 variable
}
Can anyone suggest possible issues? Should I consider other libraries for this project?
stcline:
I have successfully built a SparkFun project using an Arduino mini and a ESP8266 NodeMCU 12-E.
We will be using an AP not connected to the internet in order to run a Blynk local server. The students will connect their phones to the server and their projects using the ESP 8266 modules.
To get them started I would just like to show them how to control an LED with the app. ... For these projects they will be using the ESP8266 modules with Arduino UNOs.
Perhaps there is something I am missing.
Perhaps there is. For what you intend to do, the Uno is probably redundant. I believe there have been recent posts about using Mode-MCU in WiFi direct - no local server necessary.
Bringamosa:
I mean do you have a proper router setup or do u use an esp as accespoint. An esp as AP can (usualy) only handle 4 connections at the same time.
Bringamosa:
Maybe another thing to try is to change the routes SSID? something with only letters. Not sure if it is causing problems but just thinking along.
I changed the ssid to "mechlab". RPI, phone and laptop all connect but not the ESP8266.
Looking at your choice i suspect you are using the code that worked on your nocemcu
The esp on the uno acts as a wifi shield. So diffrent code needed.
This is the example code found under examples in your IDE
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how to use ESP8266 Shield (with AT commands)
to connect your project to Blynk.
WARNING!
It's very tricky to get it working. Please read this article:
http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
Blynk.run();
}
also you need to have a clean fresh firmware on your esp. so no sketch uploaded to it yet. otherwise you will have to flash the AT bin on it.
When you use the esp8266 on your UNO for wifi capabilities (as a shield) you put your code on the uno and the AT firmware on your esp8266.
There is an example piece in the arduino IDE
That states: This example shows how to use ESP8266 Shield (with AT commands)
to connect your project to Blynk.
If not everything is purchased already maybe a wemosd1 might be a solution. A bit less pins than a uno but enough for a couple odd sensors. Plus toy can just plug in a usb cable. And it is cheaper than a uno and esp8266-01 module together.
I appreciate the equipment suggestion from Bringamosa but I do already have the ESP8266 NodeMCU 12-Es purchased. I think I will pick up one of those wemosd1 modules for testing of future projects.
Before that though, I would like to use the NodeMCU as a standalone Arduino. What I am not understanding is that I have tested two different modules to make sure the equipment is not defective and I have gone back to a more complicated sketch from months ago. I am even connecting everything to my home network as that is where it was successfully running. It worked fine before and now the module will not connect.
I do not have extensive experience with networking but this seems pretty straightforward. Very frustrating.
stcline:
I appreciate the equipment suggestion from Bringamosa but I do already have the ESP8266 NodeMCU 12-Es purchased. I think I will pick up one of those wemosd1 modules for testing of future projects.
Before that though, I would like to use the NodeMCU as a standalone Arduino. What I am not understanding is that I have tested two different modules to make sure the equipment is not defective and I have gone back to a more complicated sketch from months ago. I am even connecting everything to my home network as that is where it was successfully running. It worked fine before and now the module will not connect.
I do not have extensive experience with networking but this seems pretty straightforward. Very frustrating.
NodemMCU and Wemos D1 mini are almost identical.
the esp8266 has a RF setting on flash. if the flash is erased or overwritten the setting is lost. the esp8266 can run without it but it is possible that the value is off and a calibration doesn't help. the esp8266 arduino boards packega doesn't write the RF settings.
The AT firmware reference has the instructions how to init this settings.
Best is to use the Espressif Flash Download Tool (Windows only) and flash files esp_init_data_default.bin and blank.bin to locations specific for different flash sizes. The FDT tool adjust settings in esp_init_data_default.bin according to chip parameters. The esptool.py doesn't change the esp_init_data_default.bin.
for 4Mbit flash (512kB)
blank.bin 0x78000 Initializes the RF_CAL parameter area.
esp_init_data_default.bin 0x7C000 Stores the default RF parameter values; the BIN has to be
downloaded into flash at least once. If the RF_CAL parameter area is initialized, this BIN has to be
downloaded too.
stcline:
What I am not understanding is that I have tested two different modules to make sure the equipment is not defective and I have gone back to a more complicated sketch from months ago. I am even connecting everything to my home network as that is where it was successfully running. It worked fine before and now the module will not connect.
I do not have extensive experience with networking but this seems pretty straightforward. Very frustrating.
The uno together with the esp8266 is not the same as a nodeMCU.
You can not upload your sketch that worked on your nodeMCU onto your arduino uno and the esp connected to that, or vica versa, the sketch loaded onto your esp and nothing on the uno.
You must use another sketch, that tells the uno that it has a esp wifi shield on it, and your esp need to have a clean AT bin installed
The nodemcu can be used as a stand alone "arduino" unit having wifi, using the code you showed us before.
Bringamosa:
The uno together with the esp8266 is not the same as a nodeMCU.
You can not upload your sketch that worked on your nodeMCU onto your arduino uno and the esp connected to that, or vica versa, the sketch loaded onto your esp and nothing on the uno.
You must use another sketch, that tells the uno that it has a esp wifi shield on it, and your esp need to have a clean AT bin installed
The nodemcu can be used as a stand alone "arduino" unit having wifi, using the code you showed us before.
I understand that it requires two different sketches: one for the esp and one for the UNO. I was able to make these work previously and had a functioning system in which the esp responded to my Blynk commands and then passed instructions to the UNO via serial pins on both boards. The only thing missing currently is connecting the esp to my AP and then allowing the local server to route commands coming from the phone app.
I can upload a simple blink led sketch to the esp successfully, my problem is just with the wifi.
Juraj:
NodemMCU and Wemos D1 mini are almost identical.
the esp8266 has a RF setting on flash. if the flash is erased or overwritten the setting is lost. the esp8266 can run without it but it is possible that the value is off and a calibration doesn't help. the esp8266 arduino boards packega doesn't write the RF settings.
The AT firmware reference has the instructions how to init this settings.
Best is to use the Espressif Flash Download Tool (Windows only) and flash files esp_init_data_default.bin and blank.bin to locations specific for different flash sizes. The FDT tool adjust settings in esp_init_data_default.bin according to chip parameters. The esptool.py doesn't change the esp_init_data_default.bin.
for 4Mbit flash (512kB)
blank.bin 0x78000 Initializes the RF_CAL parameter area.
esp_init_data_default.bin 0x7C000 Stores the default RF parameter values; the BIN has to be
downloaded into flash at least once. If the RF_CAL parameter area is initialized, this BIN has to be
downloaded too.
stcline:
I was able to make these work previously and had a functioning system in which the esp responded to my Blynk commands and then passed instructions to the UNO via serial pins on both boards.
The only thing missing currently is connecting the esp to my AP and then allowing the local server to route commands coming from the phone app.
I can upload a simple blink led sketch to the esp successfully, my problem is just with the wifi.
Since you have uploaded a simple blink on your esp, it wil not work in combination with your uno anymore. If worked before since from the factory it comes with AT bin installed. You will have to flash it again, not put asome sketch on it but foash it to work with uno again.
So for this part
The only thing missing currently is connecting the esp to my AP and then allowing the local server to route commands coming from the phone app.