EspWifiTracker
Project EspWifiTracker | |
---|---|
Location-tracker based on WiFi station ids | |
Status | In Progress"In Progress" is not in the list (Proposed, Initializing, In progress, Completed, Stalled, Abandoned) of allowed values for the "Project Status" property. |
Contact | bertrik |
Last Update | 2016-03-20 |
Status
- 2016-03-17 Can't really get the wake-up using the DS3231 to work, the interrupt pin appears to be active all the time, keeping the ESP in reset.
- 2016-03-16 Working on a prototype using a NodeMCU with a DS3231 RTC
Next steps:
- connect the RTC to the reset line of the ESP and get the mechanism going where I program an alarm in the RTC, make the ESP sleep and make it wake up by the alarm
- create a kind of blacklist/whitelist mechanism that scores each scanned AP for suitability to connect to the internet, based on AP name / security type / whether we know the password / etc. A negative score could mean that it should definitely NOT try to connect using a specific AP. The AP with the highest score is tried first
Introduction
The idea of this project is to create a simple and low-cost WiFi location tracker.
It tracks location by periodically scanning for WiFi station ids, storing those in internal memory and using one of the various location services (google, mozilla, openwlanmap, etc.) to determine a geographical location from this.
This can be used to track various things, for example:
- track your own bicycle
- know where your cat goes
- monitor movement of wild animals for research purposes, like bats or stone martens.
The basic operating principle is this:
- the tracker is in deep-sleep most of the time, keeping only a low-power real-time-clock running.
- every once in a while (say once a day) it wakes up, takes a reading of all WiFi stations in range and their signal strength. It stores these in internal memory.
- if the tracker wakes up to find an open WiFi station (or one that it knows the WiFi password of), it tries to upload all previous readings to a server.
- the server resolves the uploaded data into geographical locations using a service like Google or the Mozilla Location Service.
Tracker prototype
I'm working on a prototype of this.
Hardware
I'm basing this off an inexpensive NodeMCU clone. The NodeMCU is basically an ESP8266-module on a break-out board with an USB-serial converter and a proper 3.3V power supply. The ESP8266 is a WiFi-capable microcontroller, capable of running at 80 MHz, it has 1 MB (or more) of flash onboard which enough spare flash sectors to hold a file system.
To wake up periodically, I'm using a ZS-042 clock module, containing a Maxim DS3231 RTC chip (datasheet). This module is attached to the NodeMCU through the I2C-bus on pins D1 (SCL) and D2 (SDA). When the RTC alarm triggers, the RTC resets the ESP8266, I have yet to try this.
Software
The NodeMCU can be conveniently programmed from the "Arduino" development environment using the Arduino core for ESP8266 WiFi chip
This already comes with a library for WiFi that allows you to scan for WiFi stations
Other libraries used:
- Makuna RTC
- SPIFFS included into the esp-arduino environment
My prototype software can be found at: https://github.com/bertrik/wifitracker
It runs a simple command interpreter, type 'help' at 115200 bps to get a list of supported commands.
Server backend
The server backend receives uploads from the tracker and resolves the WiFi station ids into locations by using a location service, for example:
- Google maps geolocation API
- Mozilla Location Service
- OpenWLANmap.org (what is this project actually called?)
- see also this page on Wikipedia.
The MAC address of the ESP8266 should be unique and can be used to identify a specific tracker.
Communication between the tracker and the server is always initiated by the tracker. The protocol is REST (HTTP) and the format is JSON. I'm thinking of writing this in Java, with the use of Jackson 2.0 (JSON), Jersey 2.0 (REST) and Jetty libraries.
The REST service could have two endpoints:
- one to upload collected WiFi data from the tracker to the server
- one to download configuration data from the server to the tracker
Configuration data can be made specific for each tracker, and could consist of things like:
- a new periodic wake-up schedule
- list of known WiFi stations + passwords
- WiFi station whitelist, list of stations which are known to be really open to the internet
- WiFi station blacklist, list of stations which are open (unencrypted), but not really open to the internet
Challenges
Some things to solve yet:
- first of all make a working prototype, not necessarily optimized yet for size / appearance / battery usage / etc
- when using "WiFi hotspots": figure out how to handle so-called captive portals. Many open access points spoof DNS after connecting to the access point and re-direct you to a webpage where you either need to log in or click some 'I agree' button. It's easy for a human to understand this, possibly not so easy for an embedded device.
- figure out how to run everything from a battery, like can we run it directly off an LiFePO4 battery, or use a lithium-cobalt battery with an LDO, etc.
- make it lower power: so we can use a smaller battery or get longer tracking time
- make it smaller and lighter: so it can be attached to smaller items (e.g. a migrating bat)