This software provides a starter kit for users to be able to take a range of data and have this data published on to arbitrary MQTT topics for consumption by any application able to ingest such a stream. This includes AWS IoT.
Switch branches/tags
Nothing to show
Clone or download

Weather Data Generator

Generating streams of weather data with mqtt is made simple using this application.

By supplying a state, city, longtitude and latitude, along with a sensor name, an MQTT stream of weather data will be generated for you. This stream includes:

  • rain - measured in inches/min
  • temperature - measured in degress F
  • vibration - measured in G's
  • windspeed - in direction (degrees) and magnitude (mph)

We use the weather forecast and history API from our friends at You will need to register for their free tier here.


Using the provided CloudFormation

We have provided a very basic cloudformation template which will stand up a simple Amazon Linux EC2 instance in a stand-alone VPC with a public IP address. The cloudformation can be found at aws/cfn/stacks/weatherGen.

Three helper scripts have been provided.

  • - creates the cloudformation stack
  • - deletes an existing cloudformation stack
  • - updates the cloudformation stack

stack.json is the cloudoformation template. You should only need to update the basic pararmeters at the top of the file.

The script will provide the following output

    "Description": "VPC Id",
    "ExportName": "weatherGen-VPC-Id",
    "OutputKey": "weatherGenVPCId",
    "OutputValue": "vpc-f58cd791"
    "Description": "Public IP Address",
    "ExportName": "weatherGen-EC2-PublicIp",
    "OutputKey": "IPAddress",
    "OutputValue": ""

You can then access the EC2 instance using SSH.

ssh ec2-user@instance.ip.address -i path/to/your/key

*** Please Note: *** You will need a functional AWS account with the AWS CLI tools installed. Please refer here for how to install and configure the AWS CLI tools.

Local Installation

  • After cloning this repository, the application dependencies must be installed. you can use either NPM or yarn.

npm install or yarn install


There are 5 parameters that need to be supplied:

  • -s --sensor STRING Sensor Id
  • -t --state [STRING] State
  • -c --city STRING City
  • -lng --longtitude Longtitude
  • -lat --latitude Latitude

An exmaple command line would be

./generate.js --state "California" --city "Palo Alto" --longtitude "-122.142776" --latitude "37.399782" --sensor "sensor_1"


./generate.js --state "Washington" --city "Kent" --longtitude "-122.234840" --latitude "47.380932" --sensor “sensor_1"

Should you need to find the lat/long for a specific US city you can use this site to assit you.

The output on the command-line will look like

[2017-08-27T22:51:59.480Z]  INFO: rain_57add6cd692137b6/2035 on acbc327c2071: {"sensor_timestamp":1503874319479,"sensor_value":0,"direction":-1}
[2017-08-27T22:51:59.486Z]  INFO: temp_57fa6c97c80dcb71/2035 on acbc327c2071: {"sensor_timestamp":1503874319482,"sensor_value":58.71017678571429,"direction":-1}
[2017-08-27T22:51:59.604Z]  INFO: vib_7e60e0663c40a9a2/2035 on acbc327c2071: {"sensor_timestamp":1503874319600,"sensor_value":1.3877434481814688,"direction":-1}
[2017-08-27T22:51:59.641Z]  INFO: ws_c5a01cb911390d11/2035 on acbc327c2071: {"sensor_timestamp":1503874319641,"sensor_value":0.45,"direction":292.965}

This will generate a stream of weather data on an MQTT topic in the following format


Hence the following topics for this example are


For example


This will provide the following payload


Subscribing using mqtt

You can subscribe to the streams using any standards complaint MQTT client. For example there is a command-line node client MQTT.js and a great graphical client MQTT.fx.

Using MQTT.js you can subscribe using the following:

mqtt subscribe -h localhost -t "weather/California/Palo Alto/ws" 

or to any of the sensors, such as

mqtt subscribe -h localhost -t "weather/California/Palo Alto/temp"

This will return the stream of data such as below


Standard MQTT topic subscription masks are also supported. Consider

mqtt subscribe -h -t "#"
mqtt subscribe -h -t "weather/Washington/Kent/ws"
mqtt subscribe -h -t "weather/Washington/Kent/#"
mqtt subscribe -h -t "weather/Washington/+/#" 

Note: direction will be -1, for all non-vectorise measurements. Hence is only used in the windspeed (ws) stream.