What is Internet of Things?

Essentially they are devices that can be sensed or controlled via the internet. From house lights to kitchen gadgets, lawn care, security systems to pretty much any device we can think of.

Technically simply a device that is computer controlled and that computer inside the device is connected to a cloud interface that allows you to remotely monitor it and/or control it.

DataFlex?

No, we are not going to run DataFlex on an embedded device that wouldn’t make sense. What we are going to do is to build an IoT device and then use DataFlex to monitor and control the device

in this example I decided to create a small weather station device that allows me to monitor temperature, humidity, barometric pressure and other things such as wind speed, direction, rainfall, etc.

Particle Photon

photon1

For the device i chose a Particle Photon board. The Particle Photon is a prototyping board for IoT devices and comes with a cloud system already created for you. It is essentially a combination of a ARM Cortex microcontroller, a Broadcom Wi-Fi chip some memory and a few other components.

The Photon can be programmed using Wiring, C/C++ or even ARM assembly.

The great thing about the Photon (or the Electron which has a 3G modem instead of Wi-Fi) is that it includes the cloud service and cloud library.

When you receive your photon you can use an app on your phone to help connect the device to your Wi-Fi and then register the device on the Particle Cloud.

Once registered you can remotely control the device and/or remotely query values from the device

We are not going into detail on building the device here. We may do that in another blog. But we want to look at how we can monitor and control the device from a DataFlex application either desktop or web application.

On the device we registered a cloud variable called winfo which is filled by the device with a JSON text containing the following

Temperature
Humidity
Barometric Temperature
Barometric Pressure

we could do other information as well but for our test this should be enough

here is some example code on what that could look like on the Photon

the Photon automatically connects to the particle cloud when powered on.

Communicating with the Photon

Each photon device has a unique identifier. In addition when registered a security token is issued for the device as well. We can use a RESTful web api to communicate with the photon from our DataFlex application or any other application for that matter of course

Similar to my blog post on calling RESTful services we build a simple view that can call a RESTful service using GET. This is essentially the same as typing the URL into the address bar of your favorite browser

start with a simple view and then add the following to the top

the remote host is pointing to the particle cloud API. We also have to use SSL to create a secure connection to the cloud API

then for testing we simply show the data returned by the API

The next thing is to call the cloud API

we add a button to the view as follows

the device id is the unique id for the device. The access token is a secure access token assigned by the API when the device is registered.

the URL to query variables is as follows

winfo is the name of the variable we are querying and of course the device id and access token have to be sent.

Now we compile and run the program

After clicking the button if the device is running and connected we will get the following data returned

the data is JSON data and the field we are interested in is called ‘result’

The data in the result field is JSON data

and it reports all the values we prepared on the photon.

Now our DataFlex application can use these values and show them on screen or save them in a database, etc.

Michael Salzlechner is the CEO of StarZen Technologies, Inc.

He was part of the Windows Team at Data Access Worldwide that created the DataFlex for Windows Product before joining StarZen Technologies. StarZen Technologies provides consulting services as well as custom Application development and third party products specifically for DataFlex developers