# ESP32-ExposureAPI-Scanner

This repository contains code to scan the official COVID19 Exposure API with an ESP32 using Bluetooth LE and shows a counter on an SSD1306 OLED display.


![Device](img/esp32_scanner.jpg)

Code is based on [BLE Exposure Notification Beeper](https://github.com/kmetz/BLEExposureNotificationBeeper) which uses an LED and a piezo buzzer to notify about new detected devices but would not show the device count so I added the display part to it. You can still use the LED/Buzzer because this part is not touched in the code. In case you want to do so use this wiring:

| ESP32 pin | goes to             |
|:----------|:--------------------|
| GPIO 0    | LED (+)             |
| GPIO 2    | Buzzer (+)          |
| GND       | LED (-), Buzzer (-) |

## How it works
The official Exposure API used by Apple and Google generates new device keys approx. every 15 Minutes. The scanner remembers these codes and won't notify you again if they're detected multiple times. After 20 minutes these devices will be removed from the counter because the keys are no longer valid.

You can adjust this timespan in the code by changing `FORGET_AFTER_MINUTES`.

## Required Hardware
+ [ESP32 with in-built SSD1306 Display](https://www.aliexpress.com/item/4000217873035.html?spm=a2g0o.productlist.0.0.3cbb3f174QDsKe&algo_pvid=19b9389d-6613-4aef-bc52-59f1a4f8dfcd&algo_expid=19b9389d-6613-4aef-bc52-59f1a4f8dfcd-1&btsid=0b0a01f815926828747758917ec2d0&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_)

This ESP32 model uses these internal I²C and pins for the SSD1306 display:

| SSD1306      | goes to  |
|:-------------|:---------|
| I²C ADDRESS  | 0x3c     |
| SDA          | 5        |
| SDC          | 4        |

You can also use a separate SSD1306 but keep in mind to adjust the I²C adress and the pins in the code.

## 3D printed case
I recommend [this](https://www.thingiverse.com/thing:3821633) case from Thingiverse.

## Used Libraries
+ [ESP8266-oled-ssd1306 by ThingPulse](https://github.com/ThingPulse/esp8266-oled-ssd1306)

## To do
- [ ] [Sparklines](https://github.com/0xPIT/ESParklines)
