Help for Gunner's Coding Examples

@Gunner has started a very useful thread of Blynk coding examples at C++ Blynk - Code Examples for Basic Tasks (Work in Progress)

It’s not really a thread to discuss coding styles like the positioning of curly brackets and they can be discussed elsewhere on this site.

To keep the thread to a reasonable size I believe the expectation is that it will not be a thread for any discussion, simply a schedule of very useful sketches.

So if you have any questions about any of the sketches create a new thread in this category and provide a clear link to the actual sketch you wish to discuss.

I will kick it off with:

@Gunner in C++ Blynk - Code Examples for Basic Tasks (Work in Progress) you state the WeMos will not restart without a hard reset when it crashes with a WDT failure. Are you sure you are resetting the ESP after every local flash as this is required for ESP’s to be able to restart after a crash?

I have sketches that connect to 2 different routers that are tied to 2 different WISP’s. If one WISP goes down it will initially cause a WDT crash but it will automatically reboot and connect to the second WISP.

1 Like

Thanks!! I don’t mind doing a little housekeeping here and there, but better to not have the guests trample around in the first place :stuck_out_tongue_winking_eye:

I don’t think I did a reset at any time :blush: I know about the OTA issue, but wasn’t actually using that for flashing anyhow… but now I will have to retry with resets…

However, even without resetting after flash, I can repeatedly cause the crash by reflashing with the default v2 Prebuilt… but ONLY if there is NO WiFi signal available… if the WiFi is up, but the server is down, then no crash and it keeps running the sketch.

However with the v1.4 Prebuilt… everything keeps working regardless if loss of WiFi or just loss of the Server.

It has bugs that have been fixed in the master branch.

I am running http://arduino.esp8266.com/stable/package_esp8266com_index.json in my IDE… is that not pulling from the Master?

OK, it seems if I reset right after flashing, then even with v2 Prebuilt, it works as expected and without WDT reset… :+1:

I guess I can pull that warning out of my post… and replace it with MUST RESET AFTER FLASH VIA USB :stuck_out_tongue_winking_eye:

No it’s pulling from the latest release.

Ivan has said they will try to do a new release every couple of months and more frequently if there are major bugs to fix.

Last update was Jan so maybe next release with the bug fixes in master during March.

Most people don’t bother but it’s ESSENTIAL for every local flash.

I thought is was only an OTA thing… but know I know :slight_smile:

Thanks for the assist!!

PS what is the recommended URL for pulling from the Master… or do I need to use GIT for that?

Yes you need to use GIT but use a separate install of the IDE.

Huh… more complications… I already dislike dealing with GIT for the ESP32.

Well, I haven’t run into any serious issues so far, so will probably drag along with the boring old RELEASE version for now :wink:

Probably still need to use the prebuilt because you are using hostname in your sketch and the core bugs are associated with that.

Oh? I use that in all my running projects… what issues need I look out for? And are they documented on the espressif site somewhere?

EDIT - OK, I found reference where some device’s local IP shows 0.0.0.0. I have seen that, but only on the one same device after a few hours/days or so… it hasn’t been critical as I don’t need to update it often… and can always just manually reset it, then do the OTA update. But interesting anyhow.

Some of them are described on the ESP8266 GitHub site.

There are discussions regarding what constitutes a valid hostname i.e. underscores are not officially supported by standard XXX but Espressif were using them without any problems until recently. It might depend which standard a specific router is using to validate hostnames.

1 Like

Sorry about cluttering-up the thread with curly bracket discussions :pensive:

In example #9 @Gunner uses this code for up-time:

void UpTime() {
  Blynk.virtualWrite(V0, millis() / 1000);  // Send UpTime seconds to App
  Serial.print("UpTime: ");
  Serial.println(millis() / 1000);  // Send UpTime seconds to Serial
  digitalWrite(DeviceLED, !digitalRead(DeviceLED));  // Blink onboard LED
}

Apart from the curly brackets :angry:, there’s a minor issue that after about 50 days this up-time counter will reset to zero because millis() is and unsigned long and will eventually overflow. It’s not a big deal, but it might be worth putting a note to this effect in the code to prevent the “Why is my device resetting every 50 days, this is a bug! I’m going to sue you all” type of comment.

Pete,.

2 Likes

For those with an obsession on timing accuracy you will glad to know that the millis() drift for ESP8266, that was reported in March 2017, should be fixed when ESP8266 Core 2.5.0 is released.

ESP8266 based clocks will then be approximately 2.2 s more accurate per annum.

No problem from me… as stated, I just clean up my topic when needed. Here however your comments against my massive cooding prowess will self destruct in about 50 days :alarm_clock: :crazy_face: JK

I am just using the UpTime example from Blynk’s own examples… I don’t think I can possibly leave any device alone for that long to test without tinkering with some code :open_mouth: But since millis() is being referenced directly and not assigned to anything, perhaps it simply loops to 0 and everything carries on?

That’s my understanding, it’s just that from a user perspective it will look like the device has reset because the up-time will be back to zero again. Hence the suggestion to add a comment about that in the code.

You’re certainly a better coder than me.
I think one of my problems is that I taught myself to program in BASIC then VB and the syntax doesn’t translate into C/C++ very well. All these curly bracelets and semi colons used to drive me mad, but I think they’re finally becoming second nature. I still struggle with == instead of = and ! Instead of <>, but fortunately I’ve got plenty of time on my hands to debug my mistakes :grinning:

I think your code examples thread is a great idea and we’ll implemented. The Sketch Builder is great feature, but it it lacks a bit of appeal for some people, whereas the screenshots and videos help to bring the projects to life. Even if they’re not exactly what a user is looking for, they’re a great starting point and a learning tool for people who want to learn without begging for code.

Pete.

2 Likes

Ya, I suppose a PSA comment could apply… but then same goes for most anything I do :stuck_out_tongue:

Thank you! I appreciate the encouraging comments :smile: Make the effort worthwhile.

2 Likes