Visit Our UNIX and Linux User Community


Wuhan Coronavirus Status for China - Rapid Prototype Blynk App with ESP8266


 
Thread Tools Search this Thread
Top Forums Programming Wuhan Coronavirus Status for China - Rapid Prototype Blynk App with ESP8266
# 1  
Old 02-01-2020
Wuhan Coronavirus Status for China - Rapid Prototype Blynk App with ESP8266

Here is a rapid prototype app I just put together which might be of interest to some people.

Basically, I have parsed the data from a Chinese web site which is tracking the Wuhan coronavirus, and cache that data every minute via a local cron file and make a simple API available to a Blink app. I have not had time to DEBUG why the ArduinoJSON lib did not work (yet) for me; so my apologies for this simple string-based API and crude parsing method. However, the app, as written, does work.

If you live in an infected area in China and would like to use this app but you do not have time to build the Blynk app yourself due to the ongoing crisis in your area, please contact me in this thread (or by private email or message) and I will share this app with you at my expense (around $1 to $2 per person, up to 200 people).

Please note you do not need to run the Arduino code on an ESP8266. You can simple run the Blynk app on your mobile phone. The ESP8266 device I am running will update this Blynk app automatically. However, if you run your own Blynk app, of course that will cost me less "Blynk energy credits" (I wish Blynk would just credit me a few hundred thousand "energy credits" so I could build and provide more free public service apps during times of crisis).

Also, please reply in this discussion and with any suggestions you might have to improve this "rapid response" app, including any APIs (with relevant, credible data) you may know about. If enough people are interested, and find this helpful, I may add time-series graphs to the app.

Also, if anyone wants to improve the code below to get ArduinoJSON to work, that would be great. Then we could replace the crude parser I quickly hacked together to get this out quickly.

Hope this helps someone.

The resulting Blynk app looks like this:

Wuhan Coronavirus Status for China - Rapid Prototype Blynk App with ESP8266-img_a649273d6a9f-1jpeg


Here is the ESP8266 Arduino Code. Feel free to use the API I created (in the code):

/
Code:
*************************************************************
  Simple Blynk App for the Wuhan Virus (Version 0.1)
  Data from a key Chinese web site which publishes these stats.
  This is the same Chinese web page used by The Johns Hopkins University and others.
  You may use the code as you find useful, including the API from unix.com as a public service during this crisis.
  Neo:  The UNIX and Linux Forums - Free Tech Support  1 February 2020
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define DEBUG false
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YOUR_BLYNK_AUTHORIZATION_TOKEN";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YOUR_WIFI_SSID";
char pass[] = "YOUR_WIFI_PASSWORD";

const char *host = "www.unix.com";
const int httpsPort = 443;  //HTTPS= 443 and HTTP = 80

//The SHA1 finger print of The UNIX and Linux Forums - Free Tech Support SSL certificate
const char fingerprint[] PROGMEM = "8F 60 34 7B C0 FE CF 3C A8 2B 6D 31 6B 4B 9F C3 5B 6E A0 5F";

void setup()
{
  // Debug serial console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
 // 15 seconds init and update interval; you can easily set this to a few minutes, as the data changes slowly
  timer.setInterval(15000L, myTimerEvent); 

}

void loop()
{
  Blynk.run();
  timer.run();
}

void myTimerEvent()
{
  WiFiClientSecure httpsClient;    //Declare object of class WiFiClient

  Serial.println(host);

  Serial.printf("Using fingerprint '%s'\n", fingerprint);
  httpsClient.setFingerprint(fingerprint);
  httpsClient.setTimeout(30000); // 30 Seconds
  delay(1000);

  Serial.print("HTTPS Connecting");
  int r = 0; //retry counter
  while ((!httpsClient.connect(host, httpsPort)) && (r < 30)) {
    delay(100);
    Serial.print(".");
    r++;
  }
  if (r == 30) {
    Serial.println("Connection failed");
  }
  else {
    Serial.println("Connected to web");
  }

  String Link;
  long rssi = WiFi.RSSI();
  String macaddr = WiFi.macAddress();
  Serial.print("RSSI:");
  Serial.println(rssi);
  Serial.print("MAC: ");
  Serial.println(macaddr);
 
  // RSSI and MAC are for logging, statistical, and debugging purposes and is not shared with any third part.  You can omit RSSI and MAC if you wish, as follows:
  //Link = "/wuhan/";
  //As for me, I use RSSI and MAC because I like having this kind of data for debugging.
  Link = "/wuhan/?rssi=" + String(rssi) + "&mac=" + macaddr;
  Serial.print("requesting URL: ");
  Serial.println(host + Link);

  httpsClient.print(String("GET ") + Link + " HTTP/1.1\r\n" +
                    "Host: " + host + "\r\n" +
                    "Connection: close\r\n\r\n");

  Serial.println("request sent");

  while (httpsClient.connected()) {
    String line = httpsClient.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }

  Serial.println("reply was:");
  Serial.println("==========");
  String line;
  while (httpsClient.available()) {
    line = httpsClient.readStringUntil('\n');  //Read Line by Line
    Serial.println(line); //Print response
  }
  Serial.println("==========");
  Serial.println("closing connection");

  // crude way to parse string - should convert to json later
  int ind1 = line.indexOf(':');  //finds location of first :
  String confirmed = line.substring(0, ind1);   //captures first data String
  int ind2 = line.indexOf(':', ind1 + 1 ); //finds location of second :
  String suspected = line.substring(ind1 + 1, ind2 + 1); //captures second data String
  int ind3 = line.indexOf(':', ind2 + 1 ); //finds location of third :
  String recovered = line.substring(ind2 + 1, ind3 + 1);//captures second data String
  int ind4 = line.indexOf(':', ind3 + 1 ); //finds location of third :
  String deaths = line.substring(ind3 + 1, ind4 + 1);//captures second data String

  if (DEBUG) {
    Serial.println(String(confirmed)); Serial.println(suspected);; Serial.println(deaths); //Print response
    Serial.println(String(recovered));
  }

  if (confirmed.toInt() > 0) {
    confirmed.replace(":", ""); deaths.replace(":", ""); suspected.replace(":", "");
    recovered.replace(":", "");
    Blynk.virtualWrite(V0, confirmed.toInt());
    Blynk.virtualWrite(V1, suspected.toInt());
    Blynk.virtualWrite(V2, deaths.toInt());
    Blynk.virtualWrite(V3, recovered.toInt());

  }

}

Running and updating live from the balcony:

Wuhan Coronavirus Status for China - Rapid Prototype Blynk App with ESP8266-wemosjpeg
These 2 Users Gave Thanks to Neo For This Post:
# 2  
Old 02-01-2020
Well, I'm happy.....

From the API log files, there is already one other person using the app and the API.

So, at least one other person has found this app useful Smilie
# 3  
Old 02-01-2020
Update:

I am finding it hard to build a decent app (beyond a very basic app) with Blynk. With four labeled data displays, that "cost" met 400 x 4 = 1600 credits. That means I cannot add more of value (like another country or two's datasets for the Wuhan virus and a data chart), without getting into the “feed Blynk money”¯ business model. Blynk is starting to feel "disappointing". I was advised to “just give Blynk another 1000 free credits to share”¯; but I don't have any “free credits to share”¯ because this “very tiny app”¯ leaves me with only 400 "Blynk energy credits".

As many people know, I have a very low threshold for corporate greed, and surveillance capitalism in general, and I have promoted Blynk in the public service cause; but I think I was premature in doing so due to Blink's business model.

So, after this experiment with Blynk, I'll probably stop developing public service apps with Blynk. I have already "learned" the impression that Blynk is quite a bit more “feed me money”¯ than I care for; based on my experience with this public service app today. Unfortunately, as some know, I have a very low threshold for the "Blynk-like" business model, as I have come to understand it. Maybe I simply do not understand it?

People keep saying Blynk is "free"; but Blynk is not free for any real useful app. Everything in the app has a “cost”¯ and after we use the very tiny “2000 Blynk energy credits”¯ we have to pay real money. What am I missing? Any user created app of more than a few small data parameters exceeds the "free credits" provided by Blynk. I find today, I cannot add a chart of the Wuhan coronavirus without digging into my bank account to feed Blynk's requirement for "real coin" on a public service app. I don't have the “Blynk credits”¯ to add more countries, charts, or whatever. It's seriously - pay to play.

This Blynk business model is not designed for public service, as I have experienced over the past day.

Also, on the tech side, I do not like / appreciate it when we create a Blynk app on our phone, Blynk just “deletes it”¯ without warning. I was running a test server monitoring app one phone, and the Wuhan stats app on another phone, and Blynk just deleted the server monitoring app and replaced it with the Wuhun stats app without warning me. I'm not happy about this at all. My work on that "server monitoring app" is gone from Blynk; there appears to be no mechanism to save the Blynk app we created in the phone, so after Blynk deletes it, all that work is GONE!

Anyway, I have a low threshold for the things I am seeing with Blynk, especially after building a public service app, meant only to help others who are in crisis, and learning more about Blynk today, in the process.
This User Gave Thanks to Neo For This Post:
# 4  
Old 02-01-2020
Update:

I know why Blynk auto-deleted the Blynk app on one of my iPhones. The reason is about "money". Blynk wants our money, as soon as you get beyond a "toy" app with a few data variables. If you build any app of any substance, you will pay for it.

Blynk gives 2000 tiny toy credits for a user to build an app. But that means across all devices on same email account. So because I was running (1) a small six data point service monitoring app and (2) the Wuhan virus stats app with for data points; Blynk synced my two iPhones and deleted the small server monitoring app without warning and without saving the data for the app anywhere.

However, you can avoid having Blynk auto-delete your apps like this by having a different email for each app, LOL.

Amazing! Blynk considers deleting your Blynk app without warning or saving the app before they delete it as "their business model". Lesson Learned!

BEWARE.

My goal was to build a free public service application for those concerned about the looming coronavirus pandemic in China. I learned a lot about Blynk in the process, obviously I cannot build anything more than a "toy app" before Blynk will require coin. I am a bit in shock about this; but then again, what do we expect from corporations these days? They are all in it for the big money, right?!
This User Gave Thanks to Neo For This Post:
# 5  
Old 02-01-2020
Update:

According to the network, Blynk has apparently responded to my honest opinion and review of their product and business model by blocking our two apps we are running, but that is OK, I expected as much from the Blynk team.

I woke up this morning and built an app using Blynk to help the good people of China in a national crisis.

Now, at the end of the day, I am very unhappy, 100% of that unhappiness is because of Blynk.

Both my apps are now blocked from the Blynk network because I provided an honest assessment of their business model.

Blocked Wuhan Virus in China App (Blocked By Blynk):


Wuhan Coronavirus Status for China - Rapid Prototype Blynk App with ESP8266-blocked_blynkjpeg


My mistake in this task was in choosing Blynk for this app. I will not make that mistake again.
# 6  
Old 02-01-2020
The mistake I made in this humanitarian crisis situation was to use Blynk to build a public service app to help others.

I will not make that mistake again.

In addition, I also read the Blynk privacy policy and according to their privacy policy, they can provide the data we use on the Blynk network to third parties, for example Google and FB-like behavioral analytics, where they can partner with data miners and other third parties and user our "behavioral exhaust" without our express written consent.

From Blynk Terms of Use (TOS) policy:

Quote:
By using the [Blynk] Service, you are granting us (and any service providers or Providers used by us) permission to access your account and those messages, data, information, text, graphics, audio, video or other material and content of any kind posted/uploaded/transmitted to or through the Service using your account, to process and submit said material to End Users.
That is a very "radical" TOS statement, to say the least.......

Update:

After looking into this, I found some promising iPhone apps which do not share your data with third parties (in contrast to Blynk) and will test the mosquitto broker to set up a private pub/sub network to send and receive messages to and from these ESP8266 and ESP32 devices.

Quote:
Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.

The MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for Internet of Things messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.

The Mosquitto project also provides a C library for implementing MQTT clients, and the very popular mosquitto_pub and mosquitto_sub command line MQTT clients.
I have already set up a mosquitto broker on Ubuntu, the basic security authentication and can send a message from my ESP32 device to the remote Linux server. Will discuss this in another post.
This User Gave Thanks to Neo For This Post:
# 7  
Old 02-02-2020

Previous Thread | Next Thread
Test Your Knowledge in Computers #701
Difficulty: Easy
MySQL NOT LIKE is a sardonic DB operator used to exclude those rows which are not liked by Oracle Corporation executives.
True or False?

6 More Discussions You Might Find Interesting

1. Programming

A Slightly Better NTP Client for the ESP8266

Was not really happy with the NTP clients for the ESP8266 because, after a few years of game engine programming, I am not a fan of a lot of code and delays in the main loop, so here is a "slightly better NTP client" for the ESP8266. In a nutshell, instead of having a delay in the main loop as a... (1 Reply)
Discussion started by: Neo
1 Replies

2. Programming

Wuhan Coronavirus Status App for China - Rapid Prototype using MQTT and the IoT OnOff IOS App

With a little bit of work, was able to build a nice "Wuhan Coronavirus Status" app using MQTT and the IoT-OnOff app. More on this technique here: ESP32 (ESP-WROOM-32) as an MQTT Client Subscribed to Linux Server Load Average Messages The result turned out nice, I think. I like the look and... (10 Replies)
Discussion started by: Neo
10 Replies

3. Programming

NodeMCU ESP8266 Blynk SSL Application for Linux Server Load Averages

Here is a useful SSL (HTTPS) application for anyone with a remote Linux server they want to keep an eye on using Blynk and the NodeMCU ESP8266. This little app also works (have tested as well) on the WeMos D1 ESP8266 Arduino board. The NodeMCU setup could not be easier, just find a... (8 Replies)
Discussion started by: Neo
8 Replies

4. What is on Your Mind?

Major Changes in New UserCP (v0.63) Prototype

Regarding the latest version of the UserCP prototype (version 0.63) I have made a lot of major changes, including Added a "Posts Timeline" table for the recent posts, complimenting the non-table version earlier, which has been moved off the main menu (link at the bottom of the table). Added a... (4 Replies)
Discussion started by: Neo
4 Replies

5. Programming

Embarcadero Rapid SQL query for dependency

Team I am using Embarcadero Rapid SQL V8 . When we right click on any procedure/table/view and open the contents. It has dependencies tab, which tell what all are the dependents used . My question is how does this information captured in backend to retrieve the dependency objects in... (0 Replies)
Discussion started by: Perlbaby
0 Replies

6. Shell Programming and Scripting

Function prototype declaration

Hi All, I have the script as below #!bin/bash let k=9 if then echo "Start" Hello echo "End" else echo "failed" fi function Hello() { echo "hello !!!!" } I got the below error : (4 Replies)
Discussion started by: Balasankar
4 Replies

Featured Tech Videos