Hi everyone,
I have created project to contrl several relays and to read several sensor signals.
The already available datastreams work fine but I needed several other switch buttons, gauges etc.
For this I have paid to the Plus plan and added additional datastreams in the used template. Basically I have copied and pasted the settings from the existing integer virtual pins, but changed the names accordingly.
Nevertheless I cannot use these additional datastreams meaning, when I press a button on the mobile phone app it is not recognized by the arduino and when I want to send data from the arduino to the phone app it does not arrive there.
• Hardware: Arduino UNO WiFi Rev2 + Arduino Relay Shield
• Smartphone OS: iOS XS
• Blynk app version 1.28
• Blynk Library version: 1.2.0
• Blynk WiFiNINA_WM version: 1.1.2
IMPORTANT: I believe that the problem can be related to the template which I use. The quicktemplate and the one created by myself.
Here is my code:
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME "Polivane"
#define BLYNK_AUTH_TOKEN ""
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
int value_man = 0; //variable used to switch between manual and sensor operation. if value_man=1 do manual operation
int lights_manual = 0; //variable used to manualy switch ON/OFF the lights
int Open_GreenHouse = 0;
int Close_GreenHouse = 0;
int value_photo; //variable for the photoresistor ADC
unsigned long timer_LED_On; //variable to be used so that after 6 hr the LED light goes OFF
bool check_connection = true;
double time_irrigation = 0;
int Tap_irrigation = 0;
int Irrigation_outside = 0;
int Irrigation_Greenhouse = 0;
int Irrigation_Hose = 0;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
int status = WL_IDLE_STATUS; // the Wifi radio's status
unsigned long time1;
unsigned long time2=0;
char dbg=1;
BlynkTimer timer; // Announcing the timer
BlynkTimer timer_1; // Announcing the timer for sending data to Blynk APP
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
Close_GreenHouse = param.asInt();
Serial.println("GreenHouse manually CLOSE is pressed: ");
//Serial.println(lights_manual);
}
BLYNK_WRITE(V1)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V1 to a variable
value_man = param.asInt();
// Serial.print("Manual Button is pressed: ");
// Serial.println(value_man);
if(value_man == 1){
// Update state
//Blynk.virtualWrite(V21, 255);
Serial.println("Manual Operation ON");
//timer_LED_On = millis();
}
else {
//Blynk.virtualWrite(V21, 0);
Serial.println("Manual Operation OFF");
}
}
BLYNK_WRITE(V2)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
Open_GreenHouse = param.asInt();
Serial.println("GreenHouse manually OPEN is pressed: ");
//Serial.println(GreenHouse_Open_manual);
}
BLYNK_WRITE(V4)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
lights_manual = param.asInt();
Serial.print("Lights manually ON/OFF is pressed: ");
Serial.println(lights_manual);
}
BLYNK_WRITE(V9)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
time_irrigation = param.asDouble();
Serial.print("Time for irrigation: ");
Serial.println(time_irrigation);
}
BLYNK_WRITE(V15)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
Irrigation_Greenhouse = param.asInt();
Serial.println("GreenHouse Irrigation is pressed: ");
//Serial.println(Irrigation_Greenhouse);
}
BLYNK_WRITE(V16)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
Irrigation_outside = param.asInt();
Serial.println("Field Irrigation is pressed: ");
//Serial.println(Irrigation_Greenhouse);
}
BLYNK_WRITE(V17)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
Irrigation_Hose = param.asInt();
Serial.println("Hose Irrigation is pressed: ");
//Serial.println(Irrigation_Greenhouse);
}
BLYNK_WRITE(V20)
{
//Blynk.syncVirtual(V1);
// Set incoming value from pin V0 to a variable
Tap_irrigation = param.asInt();
Serial.println("Irrigation TAP is pressed: ");
//Serial.println(Tap_irrigation);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
Serial.println("Blynk Connected To The Cloud");
}
void setup()
{
Serial.begin(9600);
//Initialize serial and wait for port to open:
if(dbg) Serial.begin(9600);
if(dbg) while(!Serial); // wait for serial port to connect. Needed for Leonardo only
while(!ScanSSIDs()) WiFiConnect();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(5000L, LED_Command);
timer_1.setInterval(6000L, APP_DATA);
Serial.println("Setup finished");
}
//********************************************************************************************
//Function to read the soil moisture and turn on the tap irrigation
//********************************************************************************************
void APP_DATA()
{
TestWiFiConnection(); //test connection, and reconnect if necessary
long rssi=WiFi.RSSI();
if(dbg) Serial.print("RSSI:");
if(dbg) Serial.println(rssi);
}
void LED_Command()
{
//check_connection = false;
if(value_man == 1){
// Update state
Blynk.virtualWrite(V21, 255);
Serial.println("Manual Operation LED ON");
//timer_LED_On = millis();
}
else {
Blynk.virtualWrite(V21, 0);
Serial.println("Manual Operation LED OFF");
}
Serial.println("LED Command");
//check_connection = true;
}
void loop()
{
Blynk.run();
timer.run();
timer_1.run();
}
void TestWiFiConnection()
//test if always connected
{
int StatusWiFi=WiFi.status();
if(StatusWiFi==WL_CONNECTION_LOST || StatusWiFi==WL_DISCONNECTED || StatusWiFi==WL_SCAN_COMPLETED) //if no connection
{
digitalWrite(9, LOW); //LED OFF to show disconnected
if(ScanSSIDs()) WiFiConnect(); //if my SSID is present, connect
}
}
void WiFiConnect()
//connect to my SSID
{
status= WL_IDLE_STATUS;
while(status!=WL_CONNECTED)
{
status = WiFi.begin(ssid,pass);
if(status==WL_CONNECTED) digitalWrite(9, HIGH); //LED ON to show connected
else delay(500);
}
}
char ScanSSIDs()
//scan SSIDs, and if my SSID is present return 1
{
char score=0;
int numSsid = WiFi.scanNetworks();
if(numSsid==-1) return(0); //error
for(int thisNet=0;thisNet<numSsid;thisNet++) if(strcmp(WiFi.SSID(thisNet),ssid)==0) score=1; //if one is = to my SSID
return(score);
}