Hello friends of the forum. I would like to give me a hand, I am trying to get a string value from Blynk but I am not doing something right. I give you an example. But first the details of the project.
• Hardware model: NODEMCU ESP8266 + wifi connection
• web and Android client
• Blynk server
• Blynk Library updated version
ok the question is the following, I obtain the date data with the NtpClient library, and I can work with them in the program. Now my goal is to be able to send (by an if that conditions it) the value of that date to a virtual pin on the server and then be able to use blynk.Write to bring that data back to my hardware. But that part doesn’t work for me.
// in this part I get the date
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
Serial.print("DATE: ");
Serial.println(dayStamp);
diadehoy = dayStamp; //here I can work with the date in the program
Serial.print("diadehoy: ");
Serial.println(diadehoy); //this gives me the correct date
Blynk.virtualWrite(V24, diadehoy); //to send the date to blynk on virtual pin 24 i use this
//I have created in blynk a virtual string pin number 24 called "serverday"
//and my idea of being able to return that data to my device is with this (this part must be wrong)
BLYNK_WRITE(V24)
{
serverday = param.asStr();
}
//because later when I write this variable in the console it does not give me any data
Serial.print("serverday: ");
Serial.println(serverday);
Obviously I check the variables to obtain the Blynk data in the Void, I summarize them and I do not put the complete program because it is a lot of mess of temperature sensors and that works well, I have the problem here.
Writing data to a virtual pin from your sketch doesn’t trigger the corresponding BLYNK_WRITE callback. If it did, it would be very easy to get into an endless loop.
Of you want to force your BLYNK_WRITE(V24) callback to fire, you need to call a Blynk.syncVirtual(V24).
If you added some Serial.print statements into you BLYNK_WRITE(V24) callback you’d see that it wasn’t being triggered, and that your serverday string variable was empty.
void loop() {
BlynkEdgent.run();
timer.run();
while(!timeClient.update()) {
timeClient.forceUpdate();
Blynk.syncAll(); //this is what I use to synchronize the virtual pins, besides I have to use the Blynk.syncVirtual(V24).?
}
}
It’s very difficult to tell from these code snippets exactly what you are doing, but with Blynk IoT the Blynk.syncAll command only works for datastreams that have the ‘ Sync with latest server value every time device connects to the cloud’.
My advice is DO NOT USE Blynk.SyncAll.
I’m also worried that you have this in your void loop, even though it’s in an if statement.
I think you should take several steps back and start by trying to explain what your project is about, what hardware you are using, what it is that you are trying to achieve, why you aren’t getting your time from the Blynk server etc etc.
Snippets of code tell us nothing.
My project is made up of a nodemcu and 1 dht22, it takes temperature and humidity. I wanted to create a graph that shows me how many times a temperature x passes that I assign to it from a blynk menu. The graph has to tell me daily how many times it exceeds that temperature, that is, it has to count all the times that it exceeds, for example, 12 degrees and when the day changes, show that last value on the graph and return the counter to 0.
PS:: I would like to know how to get the date directly from the server. In the forums I only found through libraries.
Okay, so you want to set a temperature threshold via a widget in the app, and count how often that is exceeded during a calendar day.
I assume that if your threshold is 12 degrees and it exceeds this for two hours then drops back below the threshold this is one over-temperature event, and that if it then rises above 12 degrees again, but just for a few minutes then this is a second over temperature event?
If so, then how do you want to handle situations where the temperature hovers around the threshold- at 11.99 decrees one minute, 12.01 degrees a few seconds later, and 11.99 degrees a few seconds later?
In temperature control situations such as central heating control we use a system called hysteresis, which creates a built-in de-sensitisation system, so that a boiler/furnace or aircon system isn’t constantly turning on/of when the temperature is hovering around the target. This is achieved be requiring the temperature to have exceeded the target slightly before turning the heating off, and to have dropped slightly below the target before turning it back on again.
Do you want a similar functionality in your system, or do you want every 0.01 degree over temperature event recording separately?
I’m not really clear where your v24 usage fits into your big picture. Can you explain?
You can get the current date/time from the Blynk server using the RTC functionality. Search the documentation for RTC and you’ll find lots of info.
dear pete
I understand your point of view and I think the hysteresis method is great. Moreover, I was thinking of applying something like this for when we already control the temperature, but in principle the company asks us for a temperature excess statistic, to know how many times a certain level passes and based on that you know how many times the compressor of each chamber injects gas of cold. The logic I use to take that spike only when it occurs is as follows…
if(PICOFLAG1 == 1){}
else{if(temp1 >= MAXLIMIT1){PICOFLAG1 = 1;
Blynk.virtualWrite(V19, MAXIMO1);
}
else{}
if(temp1 < MAXLIMIT1){PICOFLAG1 = 0;
}
else{}
}
Using this I can make that as long as it does not go below the selected temperature, it does not mark another peak. But I am aware that it can happen that it changes in seconds and generates several peaks, which is not the case with this type of cold chamber.
https://drive.google.com/file/d/1UtZ5ACEQmWov7lwAxVER6wv8-SMPyzVF/view?usp=sharing
> Blockquote
@KazaDoor Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.