Examples of Datalogging Using Microcontrollers
tigoe.github.io
WiFi Datalogging
Node.js Datalogging Server
Google Sheets Datalogging Server
Tracking Time
MKR Series Datalogging
Home
This project is maintained by tigoe
This is a server that serves a webpage, its resources, and some data. It saves incoming records to a text file called data.json
, and sends items from the file when requested. This file exists even when the server is not running.
This server is written in node.js. It has a RESTful API that accepts data formatted as a JSON string in the body of a POST request. The client should send sensor readings in a POST request with a JSON body to the server. The server writes the JSON string to a text file, as diagrammed in Figure 1.
The server program is written for HTTP, not HTTPS, but if it is served from glitch.com, it will run as HTTPS. So the Arduino client in this repository is written as an HTTPS client too. If you prefer to run the servers on your own host and not use HTTPS, be sure to adjust the Arduino client accordingly.
Figure 1. System diagram of the node datalogging server
This server can be run on any host that can run node.js. You can see it running on Glitch.com at this link. It also includes a web-based client as a test example.
2021-04-02T12:48:25Z
)The JSON data in the POST request should look like this:
{
"uid": client ID (string),
"location": client physical location (string),
"lux": client lux reading (number),
"ct": client color temperature reading (number)
}
You can also include any sensor characteristics that you want to add. The Arduino example in this collection sends light and color temperature levels in lux (lux
) and degrees Kelvin (ct
), respectively. The server doesn’t check the names of the characteristics in the JSON data, so you can add anything you want.
If you want to run the server locally on your own computer, you’ll need node.js installed. Once you’ve got that done, clone this repository, and navigate to the node-datalogging-server
directory on the command line.
First, you need to install all the script’s dependencies. They are described in the package.json
file. Type the following on the command line to install them:
npm install
This will download all the libraries you need to run the script in a subdirectory called node_modules
. To run the script, type:
node server-filewriter.js
The server will run on port 8080 on your local machine. You can access it in a web browser, go to http://localhost:8080
.
To access your local server from the Arduino client in this repository, you’ll need the IP address of your computer. Change the server
variable to the IP address of your comouter and change the route
variable to /data
. Change the WiFiSSLClient
declaration to WiFiClient
and change the port
variable to 8080
which is the port on which this server is listening.
There are two clients here:
index.html
, an HTML page in /public
that sends and reads data. It reads data only from page load until the current time.