Hello, I’m having trouble connecting to a wi-fi network with Blynk. My project is a prototype environmental monitor for a local junior high school STEM/robotics class.
Hardware is:
//Arduino Uno R3
//Grove Base Shield V2.0 for Arduino
// A0 = “Grove-Loudness Sensor” Based on amplifier LM2904 & built-in microphone SeedStudio SKU 101020063
// A1 = “Grove Sound Sensor”; Grove - Sound Sensor Based on LM358 amplifier - Arduino Compatible SeedStudio SKU 101020023
// A2 = “Grove - Air quality sensor Grove - Air Quality Sensor v1.3 - Arduino Compatible” SeedStudio SKU: 101020078
// I2C = “Grove - Temp&Humi Sensor” DHT20 I2C port - SeedStudio SKU 101020932
// D6 = Grove - UART WiFi V2 (ESP8285) SeedStudio SKU: 113020011
I’m using the Arduino IDE, Blynk server , Blynk Library version 1.3.2. The quickstart example code doesn’t work:
/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "***"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>
char ssid[] = "***"; // your network SSID (name)
char pass[] = "***"; // your network password
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
This sketch simply returns:
…
[463] WiFi module not found
[463] WiFi module not found
…
I do have the Arduino IDE verbose output enabled and it complied OK.
I did have connectivity before trying Blynk, using the following code:
#include "Arduino_SensorKit.h"
#include <Arduino_BuiltIn.h>
//uncomment line below if using DHT20
#define Environment Environment_I2C
// installed library https://github.com/bportaluri/WiFiEsp
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "***"; // your network SSID (name)
char pass[] = "***"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
const int pinAdc = A1;
int loudness;
//String airQualityHistory = "";
//Sensor Setup
//#define airquality_sensor_pin 0
void setup()
{
//uncomment line below if using DHT20
Wire.begin();
Serial.begin(9600);
Environment.begin();
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
}
void loop()
{
Serial.println();
//Basic Loudness
loudness = analogRead(0);
Serial.print("Loudness Sensor: ");
Serial.println(loudness);
// delay(200);
long sum = 0;
for(int i=0; i<32; i++)
{
sum += analogRead(pinAdc);
}
sum >>= 5;
Serial.print("Sound Sensor: ");
Serial.println(sum);
// DHT20
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
Serial.print("Temperature = ");
Serial.print(Environment.readTemperature()); //print temperature
Serial.println(" C");
Serial.print("Humidity = ");
Serial.print(Environment.readHumidity()); //print humidity
Serial.println(" %");
//delay(2000);
Serial.println();
// if debug then do these:
//printCurrentNet();
//printWifiData();
delay(500);
}
void printWifiData()
{
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print your MAC address
byte mac[6];
WiFi.macAddress(mac);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
void printCurrentNet()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to
byte bssid[6];
WiFi.BSSID(bssid);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
Serial.print("BSSID: ");
Serial.println(buf);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.println(rssi);
}
Almost all the code snippets and forum posts use the older ESP8266 module…