Connect an Ambient Weather Station to ThingsBoard

At Catalina Technology, we are “Weather Bugs.” Living on Hatteras Island, we get our fair share of weather so we like to keep track of it through various IOT devices and weather stations. Since we collect a lot of data, using a tool like ThingsBoard to retrieve the data and build rules against the data coming in (alarms to tell us to close the windows when it is raining) and dashboards.

This is a demo on how you can connect an Ambient weather station to thingsboard.

First, you need to make sure you have a customer created. You can go to the customers hierarchy and either make sure you have an existing one or create a new one.

Since I have a fresh ThingsBoard site, I am just going to create a new customer called “Test Customer” and save it.

After you have a customer, click on that customer (in the customer hierarchy) and click on the Attributes Tab. What we are going to want to do is store our secret API and Application keys given to us from Ambient.

I am going to create an attribute called AMBIENTAppKey. This will be used later on when we make the API call to Ambient’s RESTful API.

I also did the same for the API key and created an attribute named AMBIENTAPIKey (NOTE: I have blurred out my keys so that someone doesnt gain access to my weather station)

Next, expand your customer and then go into the asset groups and click on All. We are going to add an asset for the weather station.

For lack of a better name, I just named my weather station asset “My Weather Station” and gave it an asset type of WeatherStation.

Now we are going to write the actual rules. Go to “Rule Chains”

We are going to create a new rule chain.

Since this rule chain is going to be retrieving data from Ambient’s RESTful API and then tying it to the asset we created, I am just going to name this “Retrieve Weather Information”

Once the rule is created, click on it and then click on the “Open rule chain” button.

Now we are going to use the “Generator” rule node. Just simply drag it out to the work surface.

What a generator rule node does is allow us to create a timer event against a particular asset or other entity in the system. In our case, we are going to just point to the Asset “My Weather Station”. And we are going to change the guts of the code to just use an empty msg.

Here is the code so that you can cut and paste

var msg = {};
var metadata = { data: 40 };
var msgType = "POST_TELEMETRY_REQUEST";

return { msg: msg, metadata: metadata, msgType: msgType };

Next, we want to get access to the customer attributes (AMBIENTAPIKey and AMBIENTAppKey) so that we can use them. Just drag the customer attributes out

A popup will be shown. Enter the below. What we are doing is taking the source attribute (tied to the customer) and then making it a variable that we can use. You could change the name of the attribute if you want. But it is just easier to keep it the same. So, make the Target attribute names the same as the Source attribute names.

Once you save the above, you will then want to link the generator node to the customer attributes. Just grab the little circle on the right of the generateor node and drag it to the left of the customer attributes node.

It will ask you what the link should be. We want to go to the next step if there is a success.

Next, drag out the rest api call node to the work surface so that we can then call Ambient’s API.

A popup will be shown. I just named this “Rest API Call” and then entered the endpoint for the Ambient API. NOTE: you will see how I replaced the actual key with a customer attribute. Also NOTE that this is a “GET” Request method.

Below is what the URL looks like with the attribute key variables embedded. What the Rest API Call node will do when it executes is replace those variables with the values stored under the customer’s attributes with the same name.

https://api.ambientweather.net/v1/devices?applicationKey=${AMBIENTAppKey}&apiKey=${AMBIENTAPIKey}

Now link the get customer attributes node to the Rest API Call node

And link it for a success.

Now we are going to write some transformation script. Search for the script node. Make sure you choose the blue one for transformation.

What we are now going to do is transform the data that comes back from Ambient and form it into an object that makes sense to save as a time series.

Below is the script so that you can cut and paste.

var returnMsg = {
    "dateutc": msg[0].lastData.dateutc,
    "winddir": msg[0].lastData.winddir,
    "windspeedmph": msg[0].lastData.windspeedmph,
    "windgustmph": msg[0].lastData.windgustmph,
    "maxdailygust": msg[0].lastData.maxdailygust,
    "tempf": msg[0].lastData.tempf,
    "hourlyrainin": msg[0].lastData.hourlyrainin,
    "eventrainin": msg[0].lastData.eventrainin,
    "dailyrainin": msg[0].lastData.dailyrainin,
    "weeklyrainin": msg[0].lastData.weeklyrainin,
    "monthlyrainin": msg[0].lastData.monthlyrainin,
    "totalrainin": msg[0].lastData.totalrainin,
    "baromrelin": msg[0].lastData.baromrelin,
    "baromabsin": msg[0].lastData.baromabsin,
    "humidity": msg[0].lastData.humidity,
    "tempinf": msg[0].lastData.tempinf,
    "humidityin": msg[0].lastData.humidityin,
    "uv": msg[0].lastData.uv,
    "solarradiation": msg[0].lastData.solarradiation,
    "feelsLike": msg[0].lastData.feelsLike,
    "dewPoint": msg[0].lastData.dewPoint,
    "feelsLikein": msg[0].lastData.feelsLikein,
    "dewPointin": msg[0].lastData.dewPointin,
    "lastRain": msg[0].lastData.lastRain,
    "tz": msg[0].lastData.tz,
    "date": msg[0].lastData.date
};

return {msg: returnMsg, metadata: metadata, msgType: msgType};

And link the Rest API Call node to the transformation script.

Making sure that we do this on success. What this will then do is take the output of the API call and pass it to the script for transformation.

Now, we just want to simply save the transformed data. It will be saved against the asset we are working on.

And link the transformation script to the time series node for success.

This is what the whole rule chain looks like.

Now we want to show this on a dashboard.

Create a new Dashboard. I am just naming it “My Dashboard”

Once the dashboard is created, open it.

Lets add a widget.

Choose the Cards widget bundle.

I am going to use the timeseries table.

You need to link the widget to data. So, what we are going to do is create a new alias to data since we dont have one already.

We are going to give it an alias name. This is just a name we can now use in this dashboard to refer to data. I am going to use a “single entity” type of filter. And I am going to point it to my Weather Station asset.

After you have pressed add to save the alias, you can then use that alias in your datasource. I am going to point to the Entity alias for “Weather Station” and then choose which data variables I want to show on my table.

I choose several variables for temperature, wind direction and speed, etc. You can drag the variables around to change the order in the table. You can also click on the pencil to edit things like header, color, etc.

After I save that, I can then see the data showing up in my timeseries table on my dashboard.

I want to do another one a bit more graphical. So, hit the plus button to add another widget.

Lets create the new widget.

What I did then was choose Analog gauge and choose the temperature gauge and then pointed the tempf field (temperature F) to be displayed.

And now I have a nice gauge. You can add as many things as you want. As well as bring in other data from other devices and assets. We also use water temperature from an ESP32 device out off of our dock to create a fully comprehensive view of weather and conditions without just getting data from one weather station.


Advanced Rules Based Integration with Catalina API for SL

Catalina’s API for Dynamics SL can be used for many things. We can retrieve all types of data from SL. We can also save transactions to SL. In this demo I did for several folks, I am taking sensor data and pushing it through an advanced rules based engine to create Service Calls in Dynamics SL.

While this demo highlights Dynamics SL, we could just as easily use these same types of rules based development to integrate with other systems like CRM, helpdesk, field service, etc. We can monitor all types of things like temperature, barometric pressure, vibrations (helpful if you an HVAC company and need to monitor your customer’s properties for problems), humidity, ambient light, flooding, and more.


PH and Temperature Hydroponic Monitor using MQTT

There have been quite a few requests for the code for my MQTT posting IOT project for testing PH and Temperature of my hydroponic towers. This code is several years old and I haven’t looked at it for at least 2. But, I figured I would put it out on GitHub.

The main purpose of this code is to monitor the PH and temperature in a water tank for my hydroponics and then use MQTT to post to io.adafruit for a dashboard.

https://github.com/dafoink/ADS1115


Catalina does IoT with MQTT

 

Catalina Technologies Integration Toolkit is IoT ready with strong MQTT connectivity.

Catalina is IOT Ready-smaller

You can subscribe to feeds on existing MQTT brokers, publish to feeds on MQTT brokers, and the Catalina Toolkit even has it’s own built in broker that can be published to which maps and routes the MQTT packets to other systems.

Features:

Subscribe to feeds

Catalina Integrator can subscribe and listen to feeds on existing brokers.  This allows you to monitor data coming in from devices and map that data to other systems and storage.  If you don’t have an existing MQTT broker, Catalina Integrator has a built in MQTT broker.

MQTTDetail

Data mapping and route to other systems

When data is received from a monitored feed, Catalina Integrator can then push it to a script and redirect it to other systems such as field service, ERP, CRM, Support, and Help Desk systems.

Scripting

Send data to an MQTT broker

So far, we have been talking about subscribing to MQTT feeds and acting on them.  But what if you need to send data to a device through MQTT?  Catalina Integrator allows you to redirect any data to an MQTT broker feed.  This means that you can send messages and control devices out in the field directly from your Service, Helpdesk, Dispatch, CRM, ERP, or other system.  Below, is an example where we are turning on lighting based on an event in the service call system in Dynamics SL.

postToMQTT


Read and Control IOT devices using SMS messaging

Over the weekend, I connected our home hydroponics system to Catalina Technologies SMS Central messaging system.  This system allows you to receive notifications from your sensors as well as even control devices just using SMS messaging.  No apps needed.  You can even control devices and get notifications from an old school flip phone.

Here is a video I took of doing simple control of lighting and hydroponics pumps just using SMS messaging.


Scheduling MQTT Messages to io.adafruit.com from Windows Task Scheduler

Often times, I want to send an MQTT message to a device so that it can automatically do something on a timed basis.  Example, say I want to turn on my greenhouse lights for my seedlings in the morning, at a certain time, and then turn them off in the evening at a certain time.  If you are using Adafruit, it has a trigger that wakes up every so many minutes, hours, days, weeks.  But, I want to have things to trigger at the same time every day.

I could use cron on one of my linux boxes.  But, in my case, I wanted to use a windows box to do the time triggering.  An easy way to do this is to use Windows Task Scheduler that comes with Windows.

Continue Reading


IOT Relay and ESP8266 to Control Lighting

Here is a quick project that I did to control lighting for our seedlings.  I wanted something that could be controlled via MQTT and then managed in Thingsboard.  On this initial prototype, I am using Adafruit’s IOT http://io.adafruit.com.  It works pretty well, but is limited in some of the features that I want (like scheduling events on a timed basis).

The components of the project are:

  • NodeMCU ESP8266 module.  I am developing in c++
  • Visual Micro plugin for Visual Studio.  Much easier for debugging and features than just the straight Arduino IDE
  • IOT Relay (See on Amazon):  This is an enclosed relay for both AC and DC switching.  And it has a simple port that allows you to control from a microcontroller.

NOTE:  I have sample code below the video. Continue Reading


PH/Temp meter now in the garden

I finally put the sensor platform out in the garden.  I am streaming it currently on io.adafruit here: https://io.adafruit.com/bwharton/garden

NOTE:  I will be moving this stream next week to Azure.  but for now, I am using MQTT to send data to adafruit’s solution.

You can see the box that I got.  It is a bit overkill.  I also got a “power stake” so that I can easily run power to both a pump and the sensor platform.  The box is very very big.  I imagine that I will get a smaller one for future versions that I will use in marine environments. Continue Reading


Cleaned up the prototype for PH sensor

wp_20170105_05_52_24_pro

I have made some changes to my PH Sensor project.  I moved it off the breadboard and did a bit of clean-up and soldered it on a perf board.  Much cleaner with screw down terminals for the external sensors.

One problem that I am having, that I have to resolve is that the probe is stuck on 2.5v.  Might be some problems with my wiring.  but it could also be the el-cheapo probe.  I’ll connect it to an Arduino and retest it outside of my project to see the results.

5165761483655009852

Here is the device in a saltwater fish pen monitoring PH to make sure the fish are in acceptable levels.

6182911483117872288

More to come.


Testing PH/Temperature sensor

I have progressed on my PH sensor project.  I have added temperature sensors (Dallas DS18B20) to measure air-temp and water-temp to augment the PH sensor.  Next will be the addition of O2 absorption as well.
I am using the following:

  1. ESP8266 wifi board (for the microcontroller)
  2. 1x DS18B20 temperature sensor that is water proof for watertemp
  3. 1x DS18B20 temperature sensor that is going to be soldered to the project board for airtemp
  4. 1x ADS1115 16bit ADC to convert the analog signal from the PH sensor to digital
  5. 1x DC to DC voltage converter to handle the required 5v for the PH sensor (the ESP8266 is 3.3v)
  6. 1x 5v Analog PH Sensor
  7. Visual Micro (yes, I am a visual studio user.  and I find that visual micro gives me much more than the Arduino IDE)

You can see the device at work.  NOTE the PH of the water is very acidic.  This is due to the fact that we had a lot of rain.  I have to get the PH back up to about 6 for the lettuce to be happy.

[youtube https://www.youtube.com/watch?v=gWC4SFbHO0Y]

After weatherproofing and hardening our prototype, we are then looking at feeding the data to an Azure IoT hub which we can then route that data to helpdesk, CRM, and field service systems for dispatching technicians to remedy any problems that could occur.  As well as have data for BI reporting.  Our integration tools for this type of thing can be seen at www.catalinatechnology.com