Vaccination Slot Notifier | CoWIN

by indoorgeek in Circuits > Electronics

1968 Views, 5 Favorites, 0 Comments

Vaccination Slot Notifier | CoWIN

Vaccination Slot Notifier | CoWIN + ESP32
IN_TN1.jpg

Hello and welcome back to another Instructable! Getting a vaccination slot in India is quite a difficult task these days, especially for the 18 to 44 age group. But I observed that there are always a few centers where 1 or 2 empty slots pop up every now and then, maybe due to rescheduling or cancellation of the slots. I decided to put electronics to work.

So in this Instructable, I will be showing you how I used an open API from the CoWIN website and made a notifier to alert me in case of empty vaccination slots.

Let's get started!

The Plan

DSC_0729.JPG

You can access the data regarding each vaccination center and day-wise appointment availability, thanks to open APIs provided by the CoWIN website. All you have to do is to enter the request URL. You will then receive the data in JSON format which needs to be deserialized to get the required data. You can choose between the following 6 APIs, it all depends on how you want to search, by pincode or by district, or by the center. These 6 can be classified into two categories. First is “findby”, which gives availability only for the date which you have entered. And the other one is “calenderBy”, which shows the availability for the next 7 days. I prefer the “calenderByCenter” one which will give the appointment availability at a particular center for the next 7 days.

I will then write a code that picks up only the useful bits from the raw JSON data, displays the information on an OLED display, and gives an audible alarm using a buzzer if there’s an empty slot.

While I was testing the code, it actually gave me an alarm for a vacant slot that had suddenly appeared and I was able to quickly book it! Well, it works!

Things You Will Need

1x ESP32-WROOM-32

1x Breakout board

1x 128x64 IIC OLED Display

1x AMS1117 3.3V Voltage Regulator

1x Buzzer

1x USB Cable

1x 10k Resistor

Tools:

3D Printer (not necessary)

Getting the Center ID

3.jpg
4.jpg
5.jpg
6.jpg

Since we are using the calenderByCenter method, we need to provide 'center ID' as an input to the API. This is how you can find the center IDs. All the APIs which I am using below can be found here.

First, you will need to know the state ID. Go to the link mentioned below and noted down the "state_id" for your state.

https://cdn-api.co-vin.in/api/v2/admin/location/st...

Once you got your state ID, you will then need a district ID. Copy the link mentioned below and replace 'state_id' with the state ID of your state. You need to note down the IDs district of the centers you want to keep an eye on.

"https://cdn-api.co-vin.in/api/v2/admin/location/districts/state_id"

Copy the link mentioned below and replace the district with yours and add today's date as well. Next, search your district for a vaccination center and copy its name.

"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict?district_id=395&date=16-06-2021"

Search the center's name using Ctrl + F. And there's the center ID!

Code

2.jpg

Before uploading the code, you need to make the following changes as shown in the image.

Make sure download and install Tone32 library for buzzer by lberstone

Enter your WiFi SSID and password.

Enter the center IDs (collected in the previous step) in the centerID[] array separated by commas.

Enter the total number of the centers entered in the above array. (Note: This needs to be fixed. I was unable to get the 'size' of the array directly using the function)

If you want to modify the code as per your needs, you can follow the next step to learn how to deserialize JSON data.

Deserializing JSON

json1.jpg
json2.jpg

Once you send the request URL, you will get raw JSON data which needs to be deserialized to get to the required data.

What is JSON?

JSON stands for JavaScript Object Notation. JSON is a lightweight format for storing and transporting data. It is usually used to read data from a web server. This is exactly what is done here as well.

JSON data is written in name/value pairs. They both are separated by colon (:)

"center_id" : "711435"

JSON Objects are written inside curly brackets { }

{"center_id" : "711435", "name" : "Fortis Hospital Kalyan W"}

JSON Arrays are written inside square brackets [ ]

"centers":[
{"center_id" : 711435 , "name" : "Fortis Hospital Kalyan W"}, 
{"center_id" : "718791" , "name" : "SRI VANI VIDYASHALA SCHOOL"}<br>]

The above array has two elements. In simple terms,

centers[0] = {"center_id" : "711435", "name" : "Fortis Hospital Kalyan W"}<br>centers[1] = {"center_id" : "718791", "name" : "SRI VANI VIDYASHALA SCHOOL"}

I will be using the same logic to get the required bits and pieces from the entire raw data provided by CoWIN website. Also, I am using the ArduinoJson library by bblanchon. This makes things a lot easier. You can use JSON viewer like this to understand the raw data.

In the first image, we can see that the array "sessions" contain 5 elements. In each element, there are many name/value pairs. For example, I want to get the value of the name 'name'.

"name" : "SRI VANI VIDYASHALA SCHOOL"

It can be passed on to a String in the following way.

String center_name = obj["sessions"][0]["name"]; //center_name = "SRI VANI VIDYASHALA SCHOOL"

Similarly for element 1,

String center_name = obj["sessions"][1]["name"]; //center_name = "KDMC ART GALLARY KALYAN W"

You can also find 'nested' arrays as shown in the second image. In other words, nested arrays are arrays inside an array. But the logic remains the same. For example, I want to get the name of the vaccine. That name/value pair is present in element '0' of an array "sessions" which is further present in element '0' of another array "centers"

String vaccine_name = obj["centers"][0]["sessions"][0]["name"]; //vaccine_name = "COVISHIELD"

3D Printing

1.jpg
20210617_115540.jpg

It is not necessary to 3D print a case. You can easily make a box using other methods.

Anyway, nothing fancy here. I made a small box in Fusion 360 with a lid and an opening for an OLED. It should be a friction fit, no screws required. I printed it using black PLA.

The STL files have been attached in this step.

Downloads

Electronics

DSC_0706.JPG
DSC_0710.JPG
DSC_0721.JPG

Make the connections as shown in the schematic. I won't be getting custom-made PCB because there are very few connections to be made. Instead, I have used an ESP32 breakout board to keep the device as small as possible. I 'free-form' soldered all the components. Since I will be powering it using 5V USB supply and ESP32 needs 3.3V, a 3.3V voltage regulator is required to reduce the voltage.

To program ESP32, I am using the FT232RL USB to UART TTL converter. You can add a female header to program the ESP32 to easily program at any time in the future.

Get any unused USB cable, cut off the ends and use it to power the device. If ESP32 is constantly restarting while connecting to WiFi, add a 10uF ceramic capacitor at the output of the 3.3V regulator.

If you do not enjoy soldering, you can also use any ESP32 development board like NodeMCU-32S and make a breadboard version instead. Also, you don't have to worry about other stuff like proper power supply and programming is easy too.

Enjoy!

DSC_0741.JPG

And finally, upload the code and power it using USB. Any USB power supply which can provide at least 1A will work. Sit back, wait and hope you get lucky!

Thank you for sticking to the end. I hope you love this project.

Get vaccinated, stay safe and I’ll see you in the next one!