/*************************************************************
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 sketch shows how to access WiFiClient directly in Blynk
NOTE: This requires Arduino UNo WIFI BOARD With 1.0.0 FIRMWARE
and WifiLynk libraries
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFiLink.h>
#include <BlynkSimpleStream.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "yyyyyyyy"; // your network SSID (name)
char pass[] = "xxxxxxx"; // your network password
int status = WL_IDLE_STATUS; // the Wifi rad
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Your Token";
//IPAddress host(192,168,1,15); // numeric IP
const char* host = "blynk-cloud.com";
WiFiClient wifiClient;
// This function tries to connect to the cloud using TCP
bool connectBlynk()
{
wifiClient.stop();
return wifiClient.connect(host, 8442);
}
//Print result connection Wifi
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
// This function tries to connect to your WiFi network
void connectWiFi()
{
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 = WiFi.begin(ssid, pass);
// wait 5 seconds for connection:
delay(5000);
}
Serial.println("Connected to wifi");
}
void setup()
{
// Debug console
Serial.begin(9600);
connectWiFi();
printWifiStatus();
connectBlynk();
Blynk.begin(wifiClient, auth);
}
void loop()
{
// Reconnect WiFi
if (WiFi.status() != WL_CONNECTED) {
connectWiFi();
return;
}
// Reconnect to Blynk Cloud
if (!wifiClient.connected()) {
connectBlynk();
return;
}
Blynk.run();
}