Tether

From Hackstrich
Revision as of 21:29, 14 April 2018 by SarahEmm (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I keep leaving my backpack behind and would like to stop doing that using technology (because I can't come up with a non-tech solution that works).

Project Status

  • 2018-04-14: Added support for base stations to the simulator and worked out a bunch of protocol details. Re-syncing won't work properly if just the TX leaves and comes back, so we need to fix that next. RSSI is included in Ack packets, but not used at all yet and not in any other packet types.
  • 2018-04-13: Started writing a simulator to get the protocol details worked out ahead of having hardware. RX and TX units work so far, no base station support.
  • 2018-04-11: Bought a TrackR after a bunch of research, it doesn't work very well at all. Started putting together idea for something that will work better. Next steps are to finish figuring out the sequences, especially for when one or both portable units go into/out of base station range. Re-syncing time slots when just the RX unit leaves and comes back seems to be the hardest problem.

Functionality Desired

  • Unit that goes in backpack has long battery life, don't want to have to worry about charging it or replacing batteries often
    • This unit can be heavier as my backpack is always heavy
  • Unit that goes in other bag can require charging more often but needs to be smaller
  • Base station unit that the other units can detect and go into a low power mode when at home/work
  • Should be able to leave my backpack at home (and maybe at work) without any alarm going off, as I do this intentionally
  • Don't want to have to build too much custom hardware, going to try to build this around COTS stuff

Basic Overview

System Components

  • RX Unit - Carried in bag that never gets left behind
  • TX Unit - Carried in bag that sometimes gets left behind
  • Base Station - Installed at home and at work
    • Puts RX/TX into a power-saving mode when nearby
    • Keeps track of accurate time and gives time updates to nearby RX/TX units

Hardware

  • RX Unit
    • Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz - RadioFruit
    • FeatherWing OLED - 128x32 OLED Add-on For All Feather Boards
    • Beeper of some kind
  • TX Unit
    • Adafruit Feather M0 with RFM95 LoRa Radio - 900MHz - RadioFruit
    • FeatherWing OLED - 128x32 OLED Add-on For All Feather Boards
  • Base Station
    • Adafruit Feather HUZZAH with ESP8266 WiFi
    • Adafruit LoRa Radio FeatherWing - RFM95W 900 MHz - RadioFruit
    • DS3231 Precision RTC FeatherWing
    • FeatherWing OLED - 128x32 OLED Add-on For All Feather Boards
    • FeatherWing Doubler (CPU and LoRa on one side, RTC and OLED on the other)

Concepts/Ideas

  • A time slot opens every BEACON_TIME-DRIFT_SAFETY seconds, lasts at least DRIFT_SAFETY/2 seconds or until a beacon is heard
  • Receiver normally synchronizes to transmitter, and listens for only a few seconds around when it expects the transmitter to send something.
  • When near a base station, everything synchronizes to the base station, listening for only a few seconds around when that sends
    • If contact with base station is lost, transmitter picks up again on the same schedule that was in use from the base station

Protocol

Variables

  • INIT_TIMEOUT=180
  • ACK_TIMEOUT=5
  • BEACON_TIME=60
  • BASE_REPORT_TIME=180
  • TIMESLOT_LENGTH=10
  • ACK_BASE_EVERY=3

Packet Formats

Beacon Packet

  • 1 byte - B
  • 1 byte - number of seconds until the next beacon will be sent
  • 1 byte - voltage on battery

Base Report Packet

  • 1 byte - R
  • 1 byte - number of seconds until the next base report will be sent
  • 1 byte - base identifier
  • 1 byte - current RTC hours
  • 1 byte - current RTC minutes
  • 1 byte - current RTC seconds

Ack Packet

  • 1 byte - A
  • 1 byte - RSSI during packet receive (0-254, higher is better, 255 means "no data")

Sequence

RX Unit

State 'Init'

  1. Listen constantly until beacon or base report heard, (or until INIT_TIMEOUT expires at which point will shut down and alert that no TX found)
  2. Transmit an ACK back and go to sleep until BEACON_TIME-TIMESLOT_LENGTH/2
  3. Transition to state 'Listening'

State 'Listening'

  1. Wake back up, listen until next beacon or until timeslot closes.
    1. If beacon heard, transition to BaseInRange state
    2. If base report heard, repeat from start of state
    3. If beacon or base report not heard before the timeout, alert the user and transition to state 'TXLost'

State 'TXLost'

  1. Go to sleep for BEACON_TIME*5
  2. Wake up, listen for BEACON_TIME+TIMESLOT_LENGTH for a beacon.
    1. If beacon or base report heard, transition back to state 'Listening'.
    2. If beacon or base report not heard, repeat from start of state.

State 'BaseInRange'

  1. Go to sleep for the received "Next Beacon In" time - TIMESLOT_LENGTH/2.
  2. Wake up and listen for TIMESLOT_LENGTH*0.75 to see if the base station is still around.
    1. If a beacon is received, send an ACK and transition back to 'Beaconing' state.
    2. If nothing received, transition to the 'TXLost' state.
    3. If a base report is received
      1. Increment the number of reports received counter
      2. If the counter is >= ACK_BASE_EVERY, send an ACK and reset the counter to zero.
      3. Repeat from start of state.

TX Unit

State 'Init'

  1. Send beacon.
  2. Wait ACK_TIMEOUT seconds for an ACK to come back.
    1. If ACK received, transition to 'Beaconing' state
  3. Go to sleep for BEACON_TIME/3
  4. Repeat from start of state

State 'Beaconing'

  1. Go to sleep for BEACON_TIME-TIMESLOT_LENGTH/2.
  2. Wake up and listen for TIMESLOT_LENGTH/2 to see if a base station is around.
  3. Listen for beacon or base report
    1. If a base report is received, transition to BaseInRange state.
    2. If nothing received, send a beacon then wait ACK_TIMEOUT seconds for ACK to come back. Log if it doesn't, but don't change behaviour.

State 'BaseInRange'

  1. Go to sleep for the received "Next Beacon In" time - TIMESLOT_LENGTH/2.
  2. Wake up and listen for TIMESLOT_LENGTH*0.75 to see if the base station is still around.
    1. If nothing received, send a beacon and transition back to 'Beaconing' state.
    2. If a base report is received
      1. Increment the number of reports received counter
      2. If the counter is >= ACK_BASE_EVERY, send an ACK and reset the counter to zero.
      3. Repeat from start of state.

Base Station Unit

State 'Init'

  1. Listen until beacon heard from TX.
  2. Transition to state 'Beaconing' when heard.

State 'BeaconSync'

  1. Go to sleep until BEACON_TIME-TIMESLOT_LENGTH/4.
  2. Wake up and send a base report.
  3. Transition to state 'Reporting'.

State 'Reporting'

  1. Go to sleep until BASE_REPORT_TIME-TIMESLOT_LENGTH/2
  2. Wake up and send a base report.
  3. Check if we've received at least one ack in the last ACK_BASE_EVERY+1 reports
    1. If not, transition back to 'Init' state.
    2. If we have, repeat from start of state.