Trying to migrate to Blynk 2.0. sorry to revive this old post but it fit my problem very closely. Thanks for reading.
Does this serial printout mean that I’m trying to connect to the legacy server?
I put at top of code:
#define BLYNK_TEMPLATE_ID “TMPLSz4tFC6X”
#define BLYNK_DEVICE_NAME “Quickstart Device”
serial printout:
3: FiOS-SO2CY Signal -86 dBm Encryption type: 4 Channel: 11
Attempting to connect to Network named: FiOS-SO2CY Westwood
Reason code: Connected
After 1 try, Wifi is connected to ssid = FiOS-SO2CY at Westwood
IP Address assigned by router to Vacuumouse: 192.168.1.174
[12948] IP: 192.168.1.174
[12977]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.6.1 on Arduino UNO WiFi Rev2
[13148] Connecting to blynk-cloud.com:80
[17110] Invalid auth token
[31147] Connecting to blynk-cloud.com:80
[31201] Invalid auth token
Code:
/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
// Comment this out to disable prints and save space
#define BLYNK_TEMPLATE_ID "TMPLSz4tFC6X"
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_PRINT Serial
#define BLYNK_AUTH_TOKEN "rKXfxxxxxxxx"
// rKXfxxxxxxxxxx
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
//#include <BlynkSimpleEthernet.h>
#include <WiFiNINA.h>
#include <SPI.h>
#include <BlynkSimpleWifi.h> //May need to install this library
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress googleDNS(8, 8, 8, 8); // google's primary DNS
const int timeZone = -5; // Eastern Standard Time (USA)
//const int timeZone = -4; // Eastern Daylight Time (USA)
EthernetUDP Udp;
unsigned int localPort = 8888; // local port to listen for UDP packets
char auth[] = BLYNK_AUTH_TOKEN;
//#define W5100_CS 10
//#define SDCARD_CS 4
#define wifiLED 2 // The wifi LED is on digital pin 2 through a 2.7k ohm resistor to ground HIGH will illuminate it.
// WiFi credentials.
// Set password to "" for open networks.
char ssid[30] = "FiOS-SO2CY"; //initialize variables but not used. alt0-2 are used below
char pass[30] = "delucawifi21";
char location[20] = "Westwood";
const int NUMBER_OF_LOCATIONS = 8; // change this to add locations and add location's ssid, pass, location text string
const int MAX_SIZE = 30;
int status = WL_IDLE_STATUS; //sets the wifi status to its initial state
//----------------------------- Enter all known wifi credentials and location descriptions here ----------------------
// For future consideration, put this data into a separate header file for privacy if you ever wanted to share this code without disclosing wifi credentials.
int locIndex = 0; // locaton index is used to index into the char array for ssid, pass and locDesc of each location
char locDesc [NUMBER_OF_LOCATIONS] [MAX_SIZE] = { // description of locations
{ "Westwood" }, // 0 locIndex V7
{ "Brownfield" }, // 1 V9
{ "Norwood" }, // 2 V8
{ "Nottingham" }, // 3 V10 "Nottingham" includes both David's house and the Lake because the ssids and passwords are the same
{ "Dedham-Erick" }, // 4 V11
{ "Sue DeLuca's iPhone" }, // 5 V12 is shared use only one at a time
{ "Dana's iPhone" }, // 6 V12
{ "Sherborn Diana's" } // 7 V12
};
char altssid [NUMBER_OF_LOCATIONS] [MAX_SIZE] = { // PUT ALL THE SSIDs HERE
{ "FiOS-SO2CY" }, // 0 Westwood locIndex
{ "CAMP" }, // 1 Brownfield locIndex
{ "Kevin1" }, // 2 Norwood locIndex
{ "Joyce" }, // 3 Nottingham locIndex
{ "Atitlan-V" }, // 4 Udi and Erick house
{ "Sue DeLuca's iPhone" }, // 5 Sue's phone as a wifi hotspot
{ "Dana's iPhone" }, // 6 Dana's phone as a wifi hotspot
{ "FeathersFinest.2.4" } // 7
};
char altpass [NUMBER_OF_LOCATIONS] [MAX_SIZE] = { // PUT ALL THE PASSWORDS HERE
{ "xxx" }, // 0 westwood
{ "xxx" }, // 1 brownfield
{ "xxx" }, // 2 norwood corrected in vers 1.82
{ "xxx" }, // 3 Nottingham
{ "xxx-para-Llevar" }, // 4
{ "xxx" }, // 5
{ "xxx" }, // 6 to add any, don't forget the comma(,) after the next to last one
{ "xxxxx"} // 7
};
//--------------------------------End of wifi credentials -----------------------------------------------------------------------
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(9600);
Serial.print(" Started up. "); Serial.print(millis()); Serial.println(" ms elapsed time");
//pinMode(SDCARD_CS, OUTPUT);
//digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
pinMode(wifiLED, OUTPUT); // pin 2 driving the LED is an output and is normally low. Used to control the green wifi LED.
digitalWrite(wifiLED, LOW); // initialize the LED off
Serial.println("Start WiFi scan of neighborhood ");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n); Serial.println(" WiFi networks found in the neighborhood.");
for (int i = 0; i < n; i++) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" \tSignal ");
Serial.print(WiFi.RSSI(i));
Serial.print(" dBm \tEncryption type: ");
Serial.print(WiFi.encryptionType(i));
Serial.print("\tChannel: ");
Serial.println(WiFi.channel(i));
/*Type of Encryption
TKIP (WPA) = 2
WEP = 5
CCMP (WPA) = 4
NONE = 7
AUTO = 8 */
delay(10);
}
}
Serial.println("");
// Wait a bit before scanning again
delay(3000);
int i = 0; // used to count while loop executions/ int could wrap and overflow which is undefined but it's only number of wifi locations
int pingResult[6];
//--------------------------------------- scan all known wifi networks -------------------
while (status != WL_CONNECTED) {
locIndex = i % NUMBER_OF_LOCATIONS; // cycles thorugh all known locations
// try all known networks sequentially one at a time
// i increments once every time through the while loop
strcpy(ssid, altssid[locIndex]); // try each alternative network
strcpy(pass, altpass[locIndex]); //
strcpy(location, locDesc[locIndex]); // record of our location retained when connected
Serial.print("Attempting to connect to Network named: ");
Serial.print(ssid); Serial.print(" "); Serial.println (locDesc [locIndex]);
WiFi.end(); // if connected, then disconnect.
// WiFi.mode(WIFI_STA); // SETS TO STATION MODE!
status = WiFi.begin(ssid, pass);
Serial.print("Reason code: ");
if (WiFi.reasonCode() == 0) {
Serial.println("Connected");
digitalWrite(wifiLED, HIGH); // illuninate wifi LED to indicate we are connected to a wifi network
} else {
Serial.print("Failed to connect because of reason code: ");
Serial.println(WiFi.reasonCode());
} //end of else
delay(000); //why? reduced to 1s in 1.97. As we increase known wifi networks to hunt for, this delays the find.
i++;
} // end of while loop
Serial.print("After "); Serial.print(i); if( i == 1) Serial.print(" try, "); else Serial.print(" tries, "); Serial.print(" Wifi is ");
Serial.print("connected to ssid = "); Serial.print(ssid); Serial.print(" at "); Serial.println(location); // at this point is ssid current? Yes.
//Serial.println(WiFi.SSID()); // redundant because ssid above is current
IPAddress ip = WiFi.localIP();
Serial.print("IP Address assigned by router to Vacuumouse: "); Serial.println(ip); // Print the IP address that the LAN router has assigned the Arduino
//Blynk.begin(auth);
// partly worked Blynk.begin(auth, ssid, pass); // but Invalid auth token
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
// You can also specify server:
Blynk.begin(auth, "blynk.cloud", 80);
//Blynk.begin(auth, 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!
}