3 Arduino - Grandson128/indoorlocation GitHub Wiki
Used Modules
Imported from Arduino IDE:
- NTPClient.h
- WiFiUdp.h
- ArduinoJson.h
- set
- string
- addons/RTDBHelper.h
Credentials
FireBase
//Host
#define DATABASE_URL "https://indoor-location-se-4383a-default-rtdb.europe-west1.firebasedatabase.app"
//Auth
#define DATABASE_SECRET "tzXOapDFPzel9sQdUBEvXAxtgbLUiYf2LGnKY9xb"
Local Wifi
//Local wifi with internet access
#define mySSID ""
#define myPASSWORD ""
Usage
To use the Arduino as a beacon it's just necessary to upload the code in the arduino/indoor_location folder to the Arduino Wemos using the Arduino IDE.
Right now the Arduino will be listening for incoming packets and calculate RSSI for the one coming from the Raspberry Pi. After calculating the RSSI a JSON like bellow will be sent to FireBase db.
{
"beacon": {
"1": { //beacon Identifier
"signal": {
"datetime": "2021-6-1 17-2-1",
"objectIdentifier": "d0:37:45:8b:33:bc",
"rssi": -81
}
}
}
}
Description
In this section we will describe how the Arduino(code uploaded) will work.
Before going into more detail we need to let be known that the Wemos built-in wifi module only works in two ways, one at a time, station_mode (works as a client) and promiscuous (works as a AP). Every operation that requires an internet connection (like send data to the remote DB) requires the wifi module to be set in station_mode while every time we want to scan for clients, the wifi module need to be set to promiscuous.
The arduino starts with synchronizing it's time by asking for the current time to a time server using the NTPClient library.
NTPClient timeClient(ntpUDP, "0.pt.pool.ntp.org", utcOffsetInSeconds);
After receiving the time from the server, we update the arduino clock with it.
Next, every 1 second:
- Enable promiscuous
- If there is a packet that as the same MAC address as our Raspberry
-
- Enable station_mode
-
- Send current packet rssi and timestamp to db
- End
if (send_) {
sendToFirebase();
send_ = false;
delay(100);
wifi_promiscuous_enable(enable);
}
More information about packet sniffing using esp8266 and our implementation