BCHDevcon 2019 Hackathon Project
Internet of Things (IoT) is gaining popularity. A good example is PurpleAir.com. Users buy a PurpleAir air pollution monitor and connect it to their wifi. The monitor submits PM2.5 data to PurpleAir server periodically. However, the user does not have many options when it comes to analyzing their own data or their neighborhood's data.
- Provide a simple API for any IoT devices or clients to post time series data to BCH.
- Proof of ownership of the data.
- Compress the raw IoT data to fully utilize the OP_RETURN field at 50% saving, 38 samples per tx.
- Provide enterprise grade tool to analyze and visualize the data.
- Increase adoption and usage of BCH via IoT devices.
- Permanent storage on BCH for user generated IoT data
- Bring Data Integration (ETL) framework to BCH to organize the OP_RETURN
- Personalized analytics
- Obtain Purple Air data feed from https://github.com/bomeara/purpleairpy/blob/master/api.md
- Select sample 4 devices devices.json
- Post datafeed to IoTBCH
- Create a template) from the json datafeed
- Compress the datafeed into byte stream.
- Push compressed data to BCH testnet in the OP_RETURN field
- Reconstruct feed from BCH OP_RETURN
- Analytics tool to visualize datafeed Live Dashboad
- Most polluted day of the week
- Air quality map
- Hourly air quality index distribution by device
- Pm2.5 Avg levels with max spike
- Air quality index heat map
- Pm2.5 Levels by device
- Pm2.5 Levels by hour
- Pm2.5 level cluster
Our RPC server is in JavaScript, it is reponsible for receiving protobuf messages (IoT device feed metrics) and creating + broadcasting BCH transactions. To generate the JS protobuf stubs:
protoc protobuf/metrics.proto --js_out=import_style=commonjs:.
To continually collect and feed the RPC server w/ device feed metrics we wrote a Golang daemon to periodically fetch and publish new metrics. To generate the Go protobuf stubs:
protoc protobuf/metrics.proto --go_out=plugins=grpc:.
npm install
npm run server
- compile feed fetcher daemon
GOOS=linux GOARCH=amd64 go build -o publish-feed-linux-amd64 .
- run
./publish-feed-linux-amd64
For PurpleAir metrics we store a Protobuf binary serialized representation of the following:
{
device: "AirMonitor_1f12",
id: 123,
lat: 37.435972,
lon: -122.129822,
temp_f: 87,
feed: [
{ ts: <start unix time>, pm2.5: <float> },
{ ts: <diff from start unix time>, pm2.5: <float> },
{ ts: <diff from start unix time>, pm2.5: <float> },
...
]
}
{ blockchain: 'BCH',
to_addr: 'qr8ngds6j7ww428mud7fz376z5vj0dn4mgx32xuv9a',
message: <Buffer 49 6f 54 5f 0a 09 70 75 72 70 6c 65 61 69 72 10 c9 75 1a 06 08 d7 95 fe dd 05 1a 02 08 50 1a 03 08 a0 01 1a 03 08 f0 01 1a 03 08 c1 02 1a 03 08 90 03 ... > }
{ txid: 'e8c5b85518febbbabfad79b90eeb461d82492ee363e34733457509d347f585f7',
vout: 2,
address: 'bchtest:qrhn96u0epjuf5d7cx3ynkht2460sm7jwcsfhvjax0',
account: 'u1',
scriptPubKey: '76a914ef32eb8fc865c4d1bec1a249daeb5574f86fd27688ac',
amount: 0.001,
confirmations: 9978,
spendable: true,
solvable: true,
safe: true }
written bytes=210 txid=9623c784a57ca650b555e9aa9e9ea59d588a2cf2e5fc498943fa5362b5e9e7c3
9623c784a57ca650b555e9aa9e9ea59d588a2cf2e5fc498943fa5362b5e9e7c3