Giter Club home page Giter Club logo

mqtt-react-weather's Introduction

MQTT React Weather

This is a demonstration of how Message Queuing Telemetry Transport (MQTT) network messaging can be integrated with React to create a simple single page application that displays live weather data.

Flow of Data

  1. WiFi or other mobile sensors publish data to an MQTT broker
  2. Node.js back-end subscribes to the MQTT broker and receives the data using MQTT.js
  3. Node.js forwards the data over Socket.IO to React
  4. React's state is updated and the data is passed down to stateless components

Prerequisites

  • An MQTT broker needs to be accessible for this project. I'm using Eclipse Mosquitto deployed to a VPS, but cloud-baed MQTT brokers are available such as AWS IoT.

    • Server environment variables:
     MQTT_SERVER='wss://your.server.com:port'
     MQTT_USERNAME=username
     MQTT_PASSWORD=password
  • WiFi equipped sensors: e.g. Particle Photon or Adafruit WICED Feather. Alternatively, MQTT publishing can be done from a shell, see notes on running.

Running

This app expects any of the following JSON parameters from the broker:

name: [STRING]
temp: [INT or FLOAT]
humidity: [INT or FLOAT]
pressure: [INT or FLOAT]
windspeed: [INT or FLOAT]
winddirection: [STRING]

The publish topic MUST be set to app; data will not be received from any other topics.

To publish to the MQTT broker from a shell, install MQTT.js globally:

npm install mqtt -g

Here is an example of a valid publish command:

mqtt pub -u 'USERNAME' -P 'PASSWORD' -h 'SERVER' -t 'app' -m '{"name": "houston", "temp": 79, "humidity": 88, "pressure": 28.95, "windspeed": 7.5, "winddirection": "SW"}'

Technologies

React React  |  Express Express  |  Node.js Node.js

MQTT.js MQTT.js  |  SOCKET.IO SOCKET.IO  |  Mosquitto Eclipse Mosquitto  |  Bootstrap Bootstrap


mqtt-react-weather's People

Contributors

lloydxmas avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.