Skip to content

sparrow-platform/sparrow-mesh

Repository files navigation

Sparrow Mesh

Sparrow Mesh is Adhoc mesh based on Android/iOS smartphones. The Mesh leverages all communication radios available on smartphones of data transfer.

Sparrow Mesh allows users to communicate within communities without having internet or additional hardware.
With sufficient number of SparrowMesh users, Sparrow Mesh can assure delivery of messages to anywhere within cities or towns.

Sparrow Mesh is Adhoc i.e it allows free movement of smartphones involved. Users simply download the app and forget about it, and they will still be helping communities to enable communication. Every single smartphone will act like a mobile tower.

Sparrow Mesh implementation is loosely based on the AODV protocol - Communication on sparrow is JSON based and every node is stateless as messages contain routing and state data. We performed extensive research to compare various Adhoc protocols. Research report can be found here -
https://github.com/sparrow-platform/sparrow-mesh/blob/master/Performance%20Evaluation%20of%20AODV.doc

Sparrow Mesh potentially has infinite overall range.
Individually, every node in Sparrow Mesh has range of:

  1. Wifi - 400m
  2. BLE/Bluetooth - 150m
  3. Sound - 30m

Mesh implementation details -

1. User Ids:
Sparrow implements a simple UserID format -
Overall format -
sourcePlatform:uniqueID

//Whatsapp username example -
whatsapp:whatsAppPhoneNumber
e.g - whatsapp:+12345678901

//FB Messenger username example - 
messenger:fbUserName
e.g - messenger:jaylohokare

//Sparrow App username example - 
sparrow:userName+deviceUniqueID
e.g - sparrow:jaylohokare123456789

2. Message format:
Any messages generated by users have a fixed JSON format:

{
"key":$messageID,
"userID":$userID,
"timeStamp":$timeStampOfMessageOrigin,
"destination":$destination,
"message":$messgeContent
}

$userID - As defined in UserIds
//e.g sparrow:jaylohokare123456789

$timeStampOfMessageOrigin - Time stamp when message was generated
//e.g 982823474842  

$messageID - $userID + '_' + $timeStampOfMessageOrigin
//e.g sparrow:jaylohokare123456789_982823474842

$destination - "sparrow" if destination is Sparrow, $destinationUserID if message is sent to someone within the mesh

$messageContent - The actual message content

3. Message upload to server:
Sparrow devices use a pub-sub based MQTT protocol for sending messages to server. The choice of MQTT was due to the low latency and low bandwidth requirement of MQTT protocol, as well as it's dynamic topic based push messaging nature.

Server IP - 18.221.210.97<br>
Server Port - 1883

We use specific MQTT topics to establish stateful data transfer. A message from a particular device is always published with a particular topic, and the corresponding responce is received by subscribing to another topic -

Publish topic - sparrow_receive/$userID
Subscribe topic - sparrow_response/$userID

4. Sparrow Mesh - Sending messges to destination:
Sparrow Mesh implements Pseudo-AODV protocol for message transfer. At physical layer, the app has Wifi, Bluetooth, BLE services running in background.
These services keep on searching for other Sparrow enabled devices and establish connections with them in round-robin fashion to transfer data.
All Sparrow devices first attempt to send data directly to servers via MQTT. If this fails, the message is added to Cache and the Mesh transfer services takes over the message.

Every Sparrow enabled device performs few simple steps every 10 seconds for every message in it's cache -

  1. Check if the message has expired - Look at Timestamp of origin and check if message has expired. If message is expired, delete the message from cache
  2. Try uploading message to server via MQTT. If successful, delete the message from cache
  3. If the message in cache was a inter-mesh message, check if the message destination is same as current device's userId. If so, delete the message from cache and create a notification saying new message was received.
  4. If message is still in cache, send the message to all nearby Sparrow devices via any available communication radio.

Project Owl ducks also receive these messages through BLE or Wifi on ESP32. When a duck receives message from Sparrow Mesh, it sends a ACK message to the sender. The sender then simply deletes the corresponding message from it's cache.

4. Sparrow Mesh - Receiving message from server
Message from server will enter Sparrow Mesh either through a online (via MQTT) sparrow app or one of the Project Owl ducks. The process for routing messages to target device is pretty much same as routing message to server.
The server response message however have slightly different format to differetiate messages originating from users from messages from server.

{
"key":$messageID,
"userID":"sparrow",
"timeStamp":$timeStampOfMessageOrigin,
"destination":$destinationUserID,
"message":$messgeContent
}


$destinationUserID - As defined in UserIds
//e.g sparrow:jaylohokare123456789

$timeStampOfMessageOrigin - Time stamp when message entered Sparrow mesh
//e.g 982823474842  

$messageID - 'sparrow_' + $destinationUserID + '_' + $timeStampOfMessageOrigin
//e.g sparrow_sparrow:jaylohokare123456789_982823474842

$messageContent - The actual message content

5. Technology used
Sparrow uses Google Nearby Connections API along with custom BLE and Wifi clients for achieving P2P mesh

For device to server MQTT connection, we use Eclpise Paho MQTT clients.

App files description -

1. Mesh service: Sparrow.Java, SparrowBLE.java
2. Message object: Message.java

Sparrow Mesh exists as a background service in smartphones. We tested Battery consumption of Sparrow mesh on multiple phones. Here are the battery utilization results:

% difference in daily battery utilization with and without Sparrow Mesh
1. Samsung Galaxy Note 9 - 1.6%
2. Pixel 2 - 2.2%
3. Moto G5 - 3.1%
4. OnePlus 6 - 1.9%
5. Nokia 7.1 - 4.2%

Check the duck-sparrow-link repo to know more about how we implemenet SparrowMesh node on Project Owl ducks (ESP32) - https://github.com/sparrow-platform/duck-sparrow-link