OPEnSLab-OSU / WeatherChimes

2 stars 1 forks source link

WeatherChimes

Completed By: Winnie Woo, Will Richards


WeatherChimes Wiki

WeatherChimes is an Internet of Things (IoT) project that uses Loom from the OPEnS lab to send weather data from an Arduino Feather M0 to Max. Much like how a wind chime converts wind information into sound, WeatherChimes strives to use a variety of weather sensors to gather data and then process that information into media like generative music and visual art for users.

Build Guide

WeatherChimes Build Guide PDF

Before Installation

Before code can be uploaded to the Feather, download the Arduino IDE software and set up the board profile to include the necessary libraries such as Loom, TSL2591, SHT30 and SDI-12, instructions for completing these steps are present in our Quick Start Guide.

Before Field Deployment

Please refer to the WeatherChimes Operation Manual for best practices in understanding and deploying WeatherChimes in the field.

Setting Up Mosquitto

Mosquitto is an MQTT broker used for handling communication with remote devices over the MQTT protocol

Setting Up MongoDB Database

MongoDB Manual\ A MongoDB instance should be running on the same server as the MQTT Broker

When data is recieved by the broker it will parse the topic out into the locations that data is stored in the database.

A basic MongoDB setup should suffice in most instances, remote access may be needed which can be completed here

It is recommended that you utilize MongoDB Clusters (specifically replica sets) for logging data as this will allow you to utilize the Max8 framework with less work.


Connecting MQTT to MongodB using Node-RED

Modifying the Node-RED flow


Loom Installation and MQTT Integration

Uploading the code to the Feather WiFi requires an USB cable. Download the code from the WeatherChimes Github repository and put WeatherChimes.ino, arduino_secrets.h and config.h in the same folder and open in Arduino. Go to Tools >> Board >> Loom SAMD boards V4 >> Loomified Feather M0. Then also check Tools >> Ports and see if the correct port has been selected and the board is appearing on said port. Upload the code to the Feather, after it has finished compiling, check to see if the upload was successful by opening the Arduino IDE serial monitor to see successful connections to the WiFi and MQTT broker as well as the packets of data being sent over the MQTT protocol.

The system clock needs to be set on the first run or when the Hypnos coin cell battery is reset. Within the weatherchimes.ino, line 141:

80 hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 10));

The sampling interval could be changed to any duration. From left to right, the numbers represent days, hours, minutes and seconds.

Getting the Arduino to connect to the internet and send to Mosquitto

The arduino_secrets.h file also needs to include the MQTT settings. The BROKER_USER and BROKER_PASSWORD correspond to the username and password set on the MQTT broker. The SECRET_BROKER is the server (IP Address / Hostname) where the MQTT Broker is listening. The BROKER_PORT is where that MQTT Broker is listening on the hostname. Finally, the SITE_NAME is not directly related to MQTT but rather the passthrough process as a whole, this tells the MongoDB server which database we should store the data in as it is passed along as the first level in the MQTT topic.

2  // Wifi settings
3  #define SECRET_SSID "Example_SSID"
4  #define SECRET_PASS "Example_Pass"
5
6  // MQTT Settings
7  #define BROKER_USER "Example_User"
8  #define BROKER_PASSWORD "Example_Pass"
9  #define SECRET_BROKER "Example.broker.mosquitto.org"
10 #define BROKER_PORT 1883
11 #define SITE_NAME "WeatherChimes" //The name of the location where these  nodes will be placed

The instance number in the WeatherChimes.ino file also needs to be changed that can be done here, where the 1 is the instance number

23 Manager manager("Chime", 1);


Max Patch set-up and usage

The main goal of setting up all of the MQTT connectivity and MongoDB storage of data was to create a seamless functionality to read data into Max.

Setting up the Max Patch

The MongoDB Connection Max Patch uses a Node.js script to connect to a database and receive live updated information.
To have the Node.js script running properly ensure that Node is installed. You can do that here.
If this is your first time using the MongoDB Max Patch and Node, click the the Setup button on the patch to install the necessary packages to run the main script for the patch.

The Setup button installs the node package manager (npm) and MongoDB node package.
The MongoDB node package can be installed using the line npm install --mongodb

Using the Max Patch

After completing the setup the user can now use the Max Patch.

To use the MongoDB Connect Max Patch, the user must input four peices of information:

  1. MongoDB admin username
  2. MongoDB admin password
  3. MongDB unique cluster variable
  4. The name of the database they would like to connect to, it should be in the Pass through script. Example: WeatherChimes
  5. The name of the device (collection) they would like to connect to. This is declared in the config file of the weathercomplete .ino Example: Chime1

After all of this information is typed into the corresponding boxes, click Send, which begins the script and connects to the MongoDB database.

Data will be streamed out of the outlet of the patch, and can be used seamlessly with the Loom Sensor Max Patch to read data.

When connected successfully, if the inlet of the Max Patch receives a bang it will output the most recent data that was sent to the connected collection. This also happens upon connecting when Send is clicked.

Further additions can be made to this Patch using the MongoDB node package to get aggregated data outputs and much more.