Sumit Kumar
Published © MIT

Coronavirus - India cases tracker

Using web integrations to keep a track on coronavirus cases in India.

BeginnerFull instructions provided1 hour504
Coronavirus - India cases tracker

Things used in this project

Hardware components

Argon
Particle Argon
×1
SparkFun Micro OLED Breakout (Qwiic)
SparkFun Micro OLED Breakout (Qwiic)
×1
Rocker Switch, VISI-ROCKER
Rocker Switch, VISI-ROCKER
×1
Battery, 3.7 V
Battery, 3.7 V
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Circuit

Code

Particle India coronavirus tracker

C/C++
Wrote in Particle online IDE.
/**--------------------------------------------------------------------------------------------------------------------------------------*
*                   India COVID-19 live status using custom ThingSpeak HTTP web communication integration                                *
*                   ----------------------------------------------------------------------------------                                   *
*                                                                                                                                        *
* Author: Sumit @ HackElectronics                                                                                                        *
* Date: April 1, 2020                                                                                                                    *
* Version: 1.0.0v                                                                                                                        *
* Language: C/C++                                                                                                                        *
* Contact: sumit.0x0ptimus@yahoo.com                                                                                                     *
* Difficulty: Begineer/Intermediate                                                                                                      *
*                                                                                                                                        *
* Feel like supporting my work? Let's join to hack the change with Sumit aka @vilaksh.                                                   *
*                                                                                                                                        *
* This program shows how to use thingspeak integration and ThingsHttp requests to fetch data from the below website,                     *
* https://www.worldometers.info/coronavirus/country/india/. Also this shows how to display battery status as a bar on top                *
*                                                                                                                                        *
*  Hardware used:                                                                                                                        *
*  1. Particle Argon x1                                                                                                                  *
*  2. Sparkfun QUIIC MicroOLED                                                                                                           *
* -------------------------------------------------------------------------------------------------------------------------------------**/

// This #include statement was automatically added by the Particle IDE.
#include <SFE_MicroOLED.h>
#include "Particle.h"
#include <Wire.h>  // Include Wire if you're using I2C

//////////////////////////
// MicroOLED Definition //
//////////////////////////
//The library assumes a reset pin is necessary. The Qwiic OLED has RST hard-wired, so pick an arbitrarty IO pin that is not being used
#define PIN_RESET 9  
//The DC_JUMPER is the I2C Address Select jumper. Set to 1 if the jumper is open (Default), or set to 0 if it's closed.
#define DC_JUMPER 1 

//////////////////////////////////
// MicroOLED Object Declaration //
//////////////////////////////////
MicroOLED oled(PIN_RESET, DC_JUMPER);    // I2C declaration

int displayTime();
int covidIndia();

int index1 = 0;
int index2 = 0;

int batHealth = 0;

String data = "";
String values = "";

String deaths = "";
String recovered = "";
String cases = "";

float voltage = analogRead(BATT) * 0.0011224;

void setup()
{ 
  Particle.subscribe("hook-response/IndiaCase", myHandler, MY_DEVICES);
  //Particle.subscribe("Calls",myCalls);
   
  delay(100);
  Wire.begin();
  oled.begin();    // Initialize the OLED
  oled.clear(ALL); // Clear the display's internal memory
  oled.display();  // Display what's in the buffer (splashscreen)
  delay(1000);     // Delay 1000 ms
  oled.clear(PAGE); // Clear the buffer.
  
 
}

void loop()
{
  displayTime();
  
  data = "";
  // Trigger the integration
  Particle.publish("IndiaCase", data, PRIVATE);
   
  covidIndia();
  //lines();
  
}

int displayTime()
{
    // Reading the voltage and convering into pixels to be rendered on screen
    voltage = analogRead(BATT) * 0.0011224;
    voltage = voltage / 3.3;
    batHealth = (int) (voltage * 63.0);
    
    //set zone as per UTC in hours format, also set it in 12 hours format
    Time.zone(+5.5);
    oled.clear(PAGE);
    oled.setFontType(1);
    oled.setCursor(12,12);
    oled.print(Time.hourFormat12());
    oled.print(":");
    oled.print(Time.minute());
    // display date as per calendar
    oled.setFontType(0);
    oled.setCursor(6,30);
    oled.print(Time.day());
    oled.print("/");
    oled.print(Time.month());
    oled.print("/");
    oled.print(Time.year());
    
    oled.line(0,0,batHealth,0);
    
    oled.display();
    delay(4000);
}


/**void myCalls(const char *event, const char *data)
{
    
}**/

void myHandler(const char *event, const char *data)
{
   /** the coming data is in this format
    *<span style=\"color:#aaa\">1,590 </span>\n\n<span>45</span>\n\n<span>148</span>
   **/
   values = data;
  
   cases = "";
   deaths = "";
   recovered = "";
   
   //finding index of ">" and "<" and extracting inbetween numbers for active cases
   index1 = values.indexOf(">");
   index2 = values.indexOf("<", index1);
   
   cases = values.substring(index1+1,index2).trim();
   
   //shortening the string for next set of number extractions
   values = values.remove(0,index2);
   
   //replacing new line escape sequences and html tags all together using space character  
   values = values.replace("</span>"," ");      
   values = values.replace("<span>"," ");
   values = values.replace("\n"," ");
   values = values.trim();               // removing trailing whitespaces
   
   /**By now we have made our data look like this 45____148 from
   <span style=\"color:#aaa\">1,590 </span>\n\n<span>45</span>\n\n<span>148</span>**/
   
   Serial.println(values);       
   
   // you may try another logic too but keep in mind we will get different numbers from integration response each time there
   //is new COVID India case
   
   index1 = values.indexOf(" ");        // find first space character and extract all digits before it
   index2 = values.lastIndexOf(" ");    // find last space character and extract all digits after it
   
   deaths = values.substring(0,index1).trim();
   recovered = values.substring(index2+1).trim();
   
   // just for debugging nothing else
   Serial.print(cases);
   Serial.print(deaths);
   Serial.print(recovered);
   
   delay(4000);
}

int covidIndia()
{
    // display India total COVID cases
    oled.clear(PAGE);
    oled.setFontType(0);
    oled.setCursor(18,12);
    oled.print("INDIA");
    
    oled.setFontType(1);
    oled.setCursor(12,30);
    oled.print(cases);
    
    oled.line(0,0,batHealth,0);
    
    oled.display();
    delay(4000);
    
    // display India COVID deaths
    oled.clear(PAGE);
    oled.setFontType(0);
    oled.setCursor(15,12);
    oled.print("DEATHS");
    
    oled.setFontType(1);
    oled.setCursor(22,30);
    oled.print(deaths);
    
    oled.line(0,0,batHealth,0);
    
    oled.display();
    delay(4000);
    
    // display India COVID recovers
    oled.clear(PAGE);
    oled.setFontType(0);
    oled.setCursor(5,12);
    oled.print("Recovered");
    
    oled.setFontType(1);
    oled.setCursor(20,30);
    oled.print(recovered);
    
    oled.line(0,0,batHealth,0);
    
    oled.display();
    delay(4000);
}

// just for OLED trial and testing
void lines()
{
  oled.clear(PAGE);
  int middleX = oled.getLCDWidth() / 2;
  int middleY = oled.getLCDHeight() / 2;
  int xEnd, yEnd;
  int lineWidth = min(middleX, middleY);
  
  for (int i=0; i<1; i++)
  {
    for (int deg=0; deg<360; deg+=15)
    {
      xEnd = lineWidth * cos(deg * PI / 180.0);
      yEnd = lineWidth * sin(deg * PI / 180.0);
      
      oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd);
      oled.display();
      delay(3);
    }
    for (int deg=0; deg<360; deg+=15)
    {
      xEnd = lineWidth * cos(deg * PI / 180.0);
      yEnd = lineWidth * sin(deg * PI / 180.0);
      
      oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd, BLACK, NORM);
      oled.display();
      delay(3);
    }
  }
}

Credits

Sumit Kumar

Sumit Kumar

32 projects • 94 followers
19 y/o. My daily routine involves dealing with electronics, code, distributed storage and cloud APIs.

Comments