Hi, I have a problem sending a string.
it is a timer.
Blynk.virtualWrite(V6, horas , “:” , minutos , “:” , segundos);
I send this plot on android it works perfect, but on iphone it doesn’t.
Could you help me I use Blynk 2.0.
Hi, I have a problem sending a string.
it is a timer.
Blynk.virtualWrite(V6, horas , “:” , minutos , “:” , segundos);
I send this plot on android it works perfect, but on iphone it doesn’t.
Could you help me I use Blynk 2.0.
@Eugene one for you to look at?
@neurona have you tried building the string first, using a temporary string variable, then sending that in your Blynk.virtualWrite command?
What type of widget are you sending this string to?
Pete.
You might want to look at the sprintf command to give you HH:MM:SS format.
Pete.
thanks Pete if I was watching it but I don’t need it that’s fine. Thank you
#include <TimeLib.h> // Time Library
#include <TinyGPS++.h> // library for GPS module
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ourWire1(12); //D6 //Se establece el pin 12 D6 como bus OneWire
OneWire ourWire2(13); //D7 //Se establece el pin 13 D7 como bus OneWire
#define rxGPS 2 //D4 alto Boot
#define txGPS 14 //D5
int inicio_T = 16; //D0 alto Boot
int rele_P = 4; //D2
//D3 gpio 0 boot error low
//D8 gpio 15 Bajo Boot
//D1 gpio 5
TinyGPSPlus gps; // The TinyGPS++ object
DallasTemperature sensors1(&ourWire1); //Se declara una variable u objeto para nuestro sensor1
DallasTemperature sensors2(&ourWire2); //Se declara una variable u objeto para nuestro sensor2
SoftwareSerial ss(rxGPS,txGPS);
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Compresor_1";
char pass[] = "1234567890";
float latitude,longitude,temp1,temp2;
float velocity; //Variable to store the velocity
byte sats; //Variable to store no. of satellites response
String bearing; //Variable to store orientation or direction of GPS
String date_str , time_str , lat_str , lng_str , Contador;
int segundos=0;
int minutos=0;
int horas=0;
unsigned long tiempoAnterior;
SimpleTimer timer;
WidgetMap myMap(V0); // V0 for virtual pin of Map Widget
unsigned int move_index = 1; // fixed location for now
//AltSoftSerial Serial_GPS;
//#define Serial_GPS Serial1 // Uncomment this line & comment
// above line to use a hardware
// Serial Port
// Change this value to suit your Time Zone
const int UTC_offset = 1; // Eastern Australia Time
time_t prevDisplay = 0; // Count for when time last displayed
//===========================================================================================================//
void Sensor_Tmp()
{
sensors1.requestTemperatures(); //Se envía el comando para leer la temperatura
temp1= sensors1.getTempCByIndex(0); //Se obtiene la temperatura en ºC del sensor 1
sensors2.requestTemperatures(); //Se envía el comando para leer la temperatura
temp2= sensors2.getTempCByIndex(0); //Se obtiene la temperatura en ºC del sensor 2
Serial.print("Temperatura 1 = ");
Serial.print(temp1);
Serial.print(" C");
Serial.print(" Temperatura 2 = ");
Serial.print(temp2);
Serial.println(" C");
//delay(100);
}
//=========================================================================================================//
void refres ()
{
Serial.print("latitud::");Serial.println( lat_str);
Serial.print("Longitude::");Serial.println( lng_str);
Serial.print("satelite::");Serial.println( sats);
Serial.print("kmph::");Serial.println( velocity);
Serial.print("Direccion::");Serial.println( bearing);
myMap.location(move_index, lng_str, lat_str, "GPS_Location");
Blynk.virtualWrite(V0, lng_str, lat_str);
Blynk.virtualWrite(V1, lat_str);
Blynk.virtualWrite(V2, lng_str);
Blynk.virtualWrite(V3, sats);
Blynk.virtualWrite(V4, velocity);
Blynk.virtualWrite(V5, bearing);
// Blynk.virtualWrite(V6, horas ,":", minutos ,":" , segundos);
Blynk.virtualWrite(V6, Contador);
Blynk.virtualWrite(V7, horas);
Blynk.virtualWrite(V9, temp1);
Blynk.virtualWrite(V10, temp2);
}
//=========================================================================================================//
BLYNK_WRITE(V8)
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
segundos = 0;
minutos = 0;
horas = 0;
Blynk.virtualWrite(V6, horas ,":",minutos,":",segundos);
timer.setTimeout(1500L, []() { Blynk.virtualWrite(V8, 0);});
}
}
//=======================================================================================================//
BLYNK_WRITE(V11)
{
int value = param.asInt(); // Get value as integer
if (value == 1)
{
digitalWrite(rele_P,HIGH);
}else{
digitalWrite(rele_P,LOW);
}
}
//======================================================================================================//
void Signal ()
{
if( (millis() - tiempoAnterior) >= 970)
{
tiempoAnterior = millis();
segundos ++;
Serial.println (String("Tiempo trabajo serial::::::: ")+horas +(":")+minutos +(":")+segundos);
}
if (segundos == 60 )
{
minutos++;
segundos = 0;
}
if (minutos == 60 )
{
horas++;
minutos = 0;
}
Contador=String(horas) + ":" + minutos +":"+ segundos;
// Serial.print("Strin_Contador:::::::");Serial.println(Contador);
}
//======================================================================================================//
void setup()
{
Serial.begin(9600);
ss.begin(9600);
pinMode(rele_P, OUTPUT);
pinMode(inicio_T, INPUT);
// digitalWrite(rele_P,HIGH);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
Blynk.begin(auth, ssid, pass);
WiFi.begin(ssid,pass ); //connecting to wifi
while (WiFi.status() != WL_CONNECTED)// while wifi not connected
{
delay(500);
Serial.print("."); //print "...."
}
Serial.println("");
Serial.println("WiFi connected");
timer.setInterval(60000L, refres);
timer.setInterval(60000L, Sensor_Tmp);
}
//============================================================================================================//
void loop()
{
timer.run();
Blynk.run();
while (ss.available() > 0) //while data is available
if (gps.encode(ss.read())) //read gps data
{
if (gps.location.isValid()) //check whether gps location is valid
{
latitude = gps.location.lat();
lat_str = String(latitude , 6); // latitude location is stored in a string
longitude = gps.location.lng();
lng_str = String(longitude , 6); //longitude location is stored in a string
sats = gps.satellites.value();
velocity = gps.speed.kmph();
bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction
}
}
bool Star = digitalRead(inicio_T);
if ( Star == true)
{
Signal ();
}
GPS_Timezone_Adjust(); // Call Time Adjust Function
}
//==========================================================================================================//
void GPS_Timezone_Adjust(){
while (ss.available()) {
if (gps.encode(ss.read())) {
int Year = gps.date.year();
byte Month = gps.date.month();
byte Day = gps.date.day();
byte Hour = gps.time.hour();
byte Minute = gps.time.minute();
byte Second = gps.time.second();
// Set Time from GPS data string
setTime(Hour, Minute, Second, Day, Month, Year);
// Calc current Time Zone time by offset value
adjustTime(UTC_offset * SECS_PER_HOUR);
}
}
// -- Delete this section if not displaying time ------- //
if (timeStatus()!= timeNotSet) {
if (now() != prevDisplay) {
prevDisplay = now();
SerialClockDisplay();
}
}
// -- Also delete the SerialClockDisplay()function ---- //
} // Keep
void SerialClockDisplay(){
// Serial Monitor display of new calculated time -
// once adjusted GPS time stored in now() Time Library
// calculations or displays can be made.
if (hour() < 10) Serial.print(F("0"));
Serial.print(hour());
Serial.print(F(":"));
if (minute() < 10) Serial.print(F("0"));
Serial.print(minute());
Serial.print(F(":"));
if (second() < 10) Serial.print(F("0"));
Serial.print(second());
Serial.print(" ");
if (day() < 10) Serial.print(F("0"));
Serial.print(day());
Serial.print(F("/"));
if (month() < 10) Serial.print(F("0"));
Serial.print(month());
Serial.print(F("/"));
Serial.println(year());
if (hour() == 21 && second()<=10 )
{
Blynk.logEvent("Informe", String("informe H/T: ") + horas);
Serial.println("cumplido.....................................");
}
}
void GPS_Timezone_Adjust(){
while (ss.available()) {
if (gps.encode(ss.read())) {
int Year = gps.date.year();
byte Month = gps.date.month();
byte Day = gps.date.day();
byte Hour = gps.time.hour();
byte Minute = gps.time.minute();
byte Second = gps.time.second();
// Set Time from GPS data string
setTime(Hour, Minute, Second, Day, Month, Year);
// Calc current Time Zone time by offset value
adjustTime(UTC_offset * SECS_PER_HOUR);
}
}here it is used to adjust the utc time.
I’m not a programmer I just understand a little Pete.