Wireless Internet Connectivity of Open-Source Scientific Devices - Part 2

Conan Mercer Applied Scientist

Wireless Internet Connectivity of Open-Source Scientific Devices - Part 2

20 May 2020 - Conan Mercer

This article was originally published in The Journal of Chemical Education - it can be cited from here</b>


JavaScript Object Notation

JavaScript Object Notation (JSON) is a syntax that uses an interchangeable data format written in human readable text for storing and exchanging data. Two structures are required when building a JSON:

  • A collection of name/value pairs, this can be realized as an object
  • An ordered list of values, this can be realized as an array
An object is an unordered set of name/value pairs. An object begins with a left brace ({) and ends with a right brace (}). Each name is followed by colon (:) and the name/value pairs are separated by a comma (, ). When using an array in JSON, begin with a left bracket ([) and end with a right bracket (]), each values are separated by a comma (, ).

Using JSON with ThingSpeak

Using JSON with ThingSpeak to upload data from sensors connected to the ESP-12E uses the same format as explained in the previous section.
The ESP-12E does not have a real-time clock, therefore the example in the code below uses the term "delta_t" as a relative timestamp. The term "TIME_STAMP" is the value assigned to "delta_t". The term "WRITE_API_KEY" is the ThingSpeak channel write API Key unique to each account.
The term "field1":"FIELD1_VALUE" is the ThingSpeak channel field, and the value to be sent to that field respectively, in the case of this project, temperature and light values.
The size of the JSON buffer determines how many values can be stored within it. This is important when considering data acquisition frequency. In this project, the reaction rate experiment, it is important to read light data every 500ms, it is therefore important to ensure the size of the JSON buffer is adequate. A JSON buffer size of 1500 is deemed sufficient for this purpose and can be found declared in the Bulk Update to ThingSpeak code at line 14. The entire JSON used in this project can also be found in here, where the JSON portion of the code is present between lines 49 and 78.

JSON Format for ThingSpeak

Putting It Together

Using C++ and the JSON format shown previously, the code used to program the ESP-12E is explained in detail in the code listing below.
Briefly, data from the LDR and IR constitutes the sensor input on the ESP-12E and is continuously stored in memory for periodic upload in bulk to a ThingSpeak channel via the Internet. Detail of how to setup a ThingSpeak channel is provided in the previous post.
ThingSpeak is limited to an upload every 15 seconds. Because data acquisition more often than once every 15 seconds is desired, the bulk upload approach overcomes this limitation.

Bulk Update to ThingSpeak