Rahul Dubey
Created April 3, 2017

Real time flood warning system

Create a real time early warning system for residents to evacuate during flash floods - like the one on 21 February in San Jose.

230
Real time flood warning system

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Avnet at&t starter kit
×1

Software apps and online services

PubNub Publish/Subscribe API
PubNub Publish/Subscribe API
Water District API

Story

Read more

Code

Creek water flow rate data

Python
This Python code fetches Creek water flow data and sends it to PubNub for analysis
import requests
import sys
import time 
from pubnub import Pubnub


def main():
    try:


        r = requests.get('http://alert.valleywater.org/datawise/dataAPI/retrievedata.php?format=json&bydate=back&days=1&tstart=&tend=&cid=1&bytype=sensor&sid=1498')

        data = r.content

        pubnub = Pubnub(publish_key="pub-c-eb2e01a2-6ef6-4f06-a022-326c57bb65ef", subscribe_key="sub-c-628af45e-1580-11e7-9093-0619f8945a4f")
        def callback(message, channel):
            print(message)


        def error(message):
            print("ERROR : " + str(message))


        def connect(message):
            print("CONNECTED")
            print pubnub.publish(channel='rahulatt', message= str(data))



        def reconnect(message):
            print("RECONNECTED")


        def disconnect(message):
            print("DISCONNECTED")



        pubnub.subscribe(channels='rahulatt', callback=callback, error=callback,
                         connect=connect, reconnect=reconnect, disconnect=disconnect)

        time.sleep(3600) # sleep for one hour

        except KeyboardInterrupt:
            sys.ext()

if __name__=="main":
    main()

Credits

Rahul Dubey

Rahul Dubey

1 project • 0 followers

Comments