This project provides a real-time monitoring system for earthquake events using data from the EMSC (European-Mediterranean Seismological Centre) RSS feed. The system retrieves earthquake data, processes it, and streams it to a Streamr node using MQTT. Users can subscribe to the Streamr node to receive real-time updates on earthquake events as they happen.
- Check out the real-time (30 seconds refresh =>
sched.every(30).seconds.do(get_and_publish_data)
)) stream deployed here!
Streamr enables efficient and secure data transfer, making it suitable for disseminating critical information such as earthquake data.
- Retrieves real-time earthquake data from the EMSC RSS feed.
- Processes and enriches earthquake data (e.g., magnitude scale description).
- Publishes earthquake events to a Streamr node using MQTT in real-time.
- Avoids publishing duplicate data for the same earthquake event.
- Modular code structure with separate modules for data extraction and publishing.
- publisher.py: The publisher script collects earthquake data from the data source, processes it, and publishes it to the Streamr stream.
- subscriboor.py: The subscriber script subscribes to the Streamr stream and receives real-time updates on earthquake events.
- Dockerfile: Dockerfile for building the Docker images for the publisher and subscriber.
- docker-compose.yml: Docker Compose file for deploying the application on Docker.
The integration of Streamr technology is implemented in the publisher.py
and subscriboor.py
files. The publisher.py
script uses the Streamr MQTT broker
to publish earthquake data to the Streamr stream. The subscriboor.py
script uses the Streamr MQTT broker
to subscribe to the stream and receive real-time updates.
In publisher.py
, the following code snippet shows how to publish data to the Streamr stream using the MQTT client:
def get_and_publish_data():
earthquake_data = get_earthquake_data()
for event in earthquake_data:
mqtt_client.publish(MQTT_TOPIC, event_json)
mqtt_client.connect(MQTT_HOST, MQTT_PORT)
mqtt_client.loop_start()
In subscriboor.py
, the following code snippet shows how to subscribe to the Streamr stream using the MQTT client:
def on_message(client, userdata, msg):
logging.info(f"Received message on topic: {msg.topic}")
logging.info(f"Message payload: {msg.payload.decode('utf-8')}")
def main():
mqtt_client.on_message = on_message
mqtt_client.connect(MQTT_HOST, MQTT_PORT)
mqtt_client.loop_forever()
if __name__ == '__main__':
main()
- Python 3.7 or higher
- Docker
- Libraries:
requests
,beautifulsoup4
,pandas
,paho-mqtt
,schedule
,pytz
- Access to a Streamr node (with MQTT plugin enabled)
- Clone the repository:
git clone https://github.com/tonykipkemboi/Streamr-Mini-Hackathon.git
- Change into the project directory:
cd Streamr-Mini-Hackathon
- Install the required Python libraries:
pip install -r requirements.txt
-
Configure the MQTT connection details in
publisher.py
(MQTT_HOST and MQTT_TOPIC). -
Set up environment variables in a
.env
file based on the.env.example
file. -
Build the Docker images using the command
docker-compose build
. -
Run the Docker containers using the command
docker-compose up
.
The earthquake data streaming service has been deployed to a DigitalOcean Droplet. The Droplet is set up as an MQTT broker to which the publisher script (publisher.py) publishes new earthquake events, and the subscriber script (subscriboor.py) subscribes to receive the events. Both the publisher and subscriber scripts run as Docker containers on the Droplet.
This project is licensed under the MIT License.
- Data Source: EMSC Earthquake RSS Feed
- MQTT Library: Paho MQTT
- Streamr: Streamr Network
- Twitter: tonykipkemboi
- GitHub: tonykipkemboi