share article

Share on facebook
Share on twitter
Share on linkedin

Setting up the Flowcode App Developer data logger

Series

By using Flowcode’s App Developer it is very easy to create and store files onto the local hard disk drive. With in-built components such as the CSV writer, a file can be easily created and loaded into Excel for chart plotting and further analysis. With a Flowcode array of open-source API components, data can be pulled from real-world electronics hardware such as, for example, a USB-connected Arduino Uno or a Wi-Fi-connected ESP32. We can use the basic analogue and digital input functionality or do more complex tasks such as collecting sensor data via a bus – an I2C, OneWire, UART or SPI, for example.

Setup

We start with creating a blank App Developer project by selecting ‘new project’ and then the ‘App Developer’ tab, then using the ‘Components Libraries’ toolbar and dragging a CSV Read/Write component from the Storage category and an API (ESP32) component from the API category.

The CSV Read/Write component has a number of macros to write and read data to and from a file on the local hard drive. We must first open a specific file using the macro OpenFile. This macro requires a filename to be entered, for example “log.csv”. In our App Developer project, we create a new property called “filename” of type a line of text which allows the app user to specify their own log files as required.

We give the property value a default that will be used when the user first loads the app.

The OpenFile macro has a second parameter which is kept should the existing contents of the file is deleted when opening. Again, the control over this is passed on to the user through creating another property, this time with the type of true or false.

We then call the OpenFile macro using the two property variables as the macro parameters. We create a Boolean-type variable with name FileOK to store the return which tells us if the file was created/opened successfully.

Now the log file is open, we can add data to it by using the AddNumber or AddString macros. Calling these macros adds the specified value to the file as an ASCII string of characters, followed by a comma, which automatically moves horizontally from column to column in the CSV file. When we want to move downwards onto a new row and back to the first column we use the NextRow macro.

The only other macro we may need to be aware of is the CloseFile. This can be used if you are opening and closing files during the operation of the app. If just opening a single file and writing to it for the duration of the app, the CloseFile macro is already called when the app is closed or stopped.

The API (ESP32) component

The API component allows us to connect to our target electronics to gather real-world data. The API hardware, be that an ESP or Arduino, etc., must first be pre-programmed with the API firmware from the Flowcode wiki (https://www.flowcode.co.uk/wiki/index.php?title=Components#API_Slave_Devices).

Specific to the ESP32 device, you first need to join it to your existing Wi-Fi network and then find out the IP address to communicate with it. Details of how to do this are available here: https://www.flowcode.co.uk/wiki/index.php?title=Component:_SCADA_(ESP32)_(SCADA_Slaves)#Detailed_description

Before we can start communicating with the API hardware, we must do a couple of things: First, we need to expose some of the component properties to the user. We do this by first selecting the component on the panel or at the top of the ‘properties’ window. We then select the properties we want to user to have access to and then right-click to ‘Expose’ to top level. For the ESP API this just includes the ESP IP address; for Arduino, it might include the COM port. Then, refresh properties.

Once we have exposed the properties, we call the macro to initialise it; this opens a specific communications channels to the hardware.

To read specific pins as analogue or digital, we simply call the ADCSample8/10 and IOGetInputPin macros, as required. Each analogue or digital sample can be stored into a variable before being passed into the CSV file using the AddNumber macro. The API component wiki page lists the specific-hardware pin connections of the analogue and digital channels.

 

 

API components and libraries

To use the API components and adjoining hardware to monitor a more complex value such as an output from a sensor connected via a bus can be done by dragging on the component for the sensor. The sensor should have a property called ‘simulate comms’ which virtualises the bus communications. Then, by pointing the sensor’s API property to the API component we can use the virtualised comms to drive real-world comms.

Connections for the bus can, again, be found on the wiki page for the API component. Then it should just be a case of initialising and sampling the sensor like with any embedded device.

 

Exporting the project as an application

Once you’re done and the project runs well in simulation, you can export it into a shared application by clicking File -> Export -> Deploy as Flowcode App. This brings up a menu with various settings, where you can choose from various panels and views. The minimal setup includes the properties window, to allow the user to configure the required settings before running the app. The Components and Resources tabs should pretty much take care of themselves without having to touch them, unless you need to embed resources such as bitmaps or audio files into the project export.

The main decision is whether or not to Bundle the App Developer runtime. Bundling the runtime allows for a single self-contained folder you can zip up and pass around, but the downside is its size – a couple dozen MB. Not bundling the runtime will provide a much smaller file that is easier to distribute – but at the cost of having to download the runtime from the Flowcode download page: https://flowcode.co.uk/resources/software/FlowcodeRuntimeV9_Installer.msi

And this is just the basics of creating a data logging application. A lot more could be added into the app, including graphs, multiple data sources and controlling outputs and recordings.

Share this article

Share on facebook
Share on twitter
Share on linkedin

Related Posts

View Latest Magazine

Subscribe today

Member Login