The SparkFun DataLogger IoT - 9DoF shown below,
is a great portable data logger board that can be used for collecting data from the internal sensors and external ones via Qwiic using these cables. Please refer to the inital setup described in this link if needed. So at this point it is assumed that the SparkFun DataLogger IoT - 9DoF has been configured with the WiFi connection.
For this setup a Raspberry Pi 5 with WiFi will be used. A simple NodeJS HTTP Server that will run inside the Raspberry Pi 5 is configured. The Node JS is an open-source, cross-platform JavaScript runtime environment to create servers. The HTTP connection in the DataLogger IoT is used to post data to this HTTP server. The Node JS is installed as follows,
$ sudo apt install nodejs npm
Once Node.js is installed, it can host a website, along with using npm to install any required JavaScript packages as needed. To make sure this installation is working, check your ip address using ifconfig command, then open an editor, change hostname ip address to the one assigned by the WiFi router (in this case 192.168.11.148) and save this file in a directory as test.js
const http = require('http');
const hostname = '192.168.11.148';
const port = 8080;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Welcome to Digikey');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Then start the Node JS HTTP Server,
$ node test.js
Server running at http://192.168.11.148:8080/
Use the CTRL-C to stop this server as needed, otherwise it will keep running in the background (it will not let you restart it), so if that happens and this error shows up,
Emitted 'error' event on Server instance at..... etc...
just perform the next command and kill the server filtered by port in this case as 3000 to start a new one as needed,
$ sudo lsof -i :3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 13640 digikey 18u IPv4 40858 0t0 TCP localhost:3000 (LISTEN)
node 13640 digikey 22u IPv4 44211 0t0 TCP localhost:3000->localhost:44892 (CLOSE_WAIT)
$ kill -9 13640
Goto the web broswer and point to the applicable IP address: example (http://192.168.11.148:8080) and the following message will show up in the browser,
Since the installation has been verified, the Node JS server can be stopped via CTRL-C.
Configure the SparkFun DataLogger IoT - 9DoF for the Node JS server via the USB cable, connect via minicom as follows,
minicom -D /dev/ttyUSB0 -b 115200 -7
Please press the reset button located next to the USB connector on the board. Navigate via the menu as shown below (To enable and setup HTTP IoT - An HTTP IoT data connector option IP address:Port)
SparkFun DataLogger IoT - 9DoF (c) 2023-2024 SparkFun Electronics
Version: 01.02.00 Version 1.2 - build 00013e
Device ID: SFD1B805D422C930
Time: 1970-12-31T17:13:39
Uptime: 0 days, 00:13:39.868
Settings for: /SparkFun DataLogger IoT - 9DoF
1) Settings - System settings and operations
2) Devices Settings - Settings for connected devices
x) Exit
Select Option: 1
Settings for: /SparkFun DataLogger IoT - 9DoF/Settings
General
1) Application Settings - Main Application Settings
2) Save Settings - Save, Restore and Reset System settings.
3) Time Setup - Manage time configuration and reference sources
Network
4) WiFi Network - WiFi network connection for the system
5) NTP Client - NTP Time Sync Client
Logging
6) Logger - Data logging action
7) Logging Timer - Set the internal between log entries
8) Data File - Output file rotation manager
IoT Services
9) MQTT Client - A generic MQTT Client
10) MQTT Secure Client - A secure MQTT client
11) AWS IoT - Connect to an AWS Iot Thing
12) ThingSpeak MQTT - Connection to ThingSpeak
13) Azure IoT - Connection to Azure IoT
14) HTTP IoT - An HTTP IoT data connector
15) Machinechat - Connection to Machinechat IoT Server
16) Arduino IoT - Connection to Arduino IoT Cloud
Preview
17) IoT Web Server - Browse and Download log files on the SD Card
Advanced
18) System Update - Device Reset and Firmware Update Options
b) Back
Select Option: 14
Settings for: /SparkFun DataLogger IoT - 9DoF/Settings/HTTP IoT
Settings
1) Enabled - Enable or Disable the HTTP Client : true
2) URL - URL to call with log information : http://192.168.11.148:800
3) CA Cert Filename - File to load the certificate from :
b) Back
Select Option:
then go back to the main menu pressing b (Back) as needed and then x (Exit) to store the configuration. If the SparkFun DataLogger IoT - 9DoF remains connected via the USB cable to the minicom terminal it will start displaying collected data via the terminal. At this point, open a new editor and enter the Node JS application called server.js, that will allow the user to display the JSON format sensor data to be displayed in the web browser,
const http = require('http');
const hostname = '192.168.11.148';
const port = 8080;
var DATA;
// Setup the endpoint server
const myServer = http.createServer(function (req, res) {
// on data callback, collect chunk
req.on('data', function(chunk){
DATA = JSON.stringify(JSON.parse(chunk),null,2);
console.log(DATA);
});
// Display Data
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(DATA);
// Listen on our port
}).listen(8080);
then after saving this file as server.js then start the Node JS server as follows,
$ node server.js
{
"MAX17048": {
"Voltage (V)": 4.349999905,
"State Of Charge (%)": 120.5976563,
"Change Rate (%/hr)": 1.248000026
},
"ISM330": {
"Accel X (milli-g)": -106.8720016,
"Accel Y (milli-g)": -1001.864014,
"Accel Z (milli-g)": 173.4840088,
"Gyro X (milli-dps)": 35,
"Gyro Y (milli-dps)": -210,
"Gyro Z (milli-dps)": 192.5,
"Temperature (C)": 27.72265625
},
"MMC5983": {
"X Field (Gauss)": -1.454711914,
"Y Field (Gauss)": 0.646850586,
"Z Field (Gauss)": -1.508666992,
"Temperature (C)": 30
}
....
the server running in the Raspberry Pi 5 will display in the terminal, the JSON data being received at the rate defined in the settings from the SparkFun DataLogger IoT - 9DoF. In the terminal the data from each device inside the board is displayed in JSON format as is being collected.
Proceed to open a new web browser in the Raspberry Pi 5 and the JSON data will display as the data is being colleced,
Any other device connected to the WiFi router in the LAN can access the SparkFun DataLogger IoT - 9DoF. In the terminal the MAX17048 micropower current fuel gauge, the ST ISM330 accelerometer/gyro inertial module and the High Performance 3-axis Magnetic Sensor. data from each device data via a web browser, for example if it’s connected to a WiFi Hotspot in the cellphone as shown below,
the data will be updated when the web browser is refreshed. Now any Android OS Developer can easily use this data to develop IoT applications in the cellphone.
If this data needs to be collected within python inside the Raspberry Pi 5, the following script developed here at Digikey called display.py,
import pandas as pd
import requests
from pandas import json_normalize
url = "http://192.168.13.144:8080/"
response = requests.get(url)
data = pd.json_normalize(response.json())
headers = []
for items in data.head():
headers.append(items)
info = data.head(1)
for items in headers:
print(items," = ", info[items][0])
can be used to collect the data from the JSON Node JS server in the Raspberry Pi 5 and will display it as follows,
$ python3 display.py
MAX17048.Voltage (V) = 4.35125017
MAX17048.State Of Charge (%) = 120.5976563
MAX17048.Change Rate (%/hr) = 0
ISM330.Accel X (milli-g) = -110.0439987
ISM330.Accel Y (milli-g) = -1002.230042
ISM330.Accel Z (milli-g) = 169.8240051
ISM330.Gyro X (milli-dps) = -157.5
ISM330.Gyro Y (milli-dps) = -1645
ISM330.Gyro Z (milli-dps) = 140
ISM330.Temperature (C) = 30.6875
MMC5983.X Field (Gauss) = -1.441833496
MMC5983.Y Field (Gauss) = 0.628723145
MMC5983.Z Field (Gauss) = -1.465515137
MMC5983.Temperature (C) = 33
The MAX17048, the ST ISM330 accelerometer/gyro inertial module and the High Performance 3-axis Magnetic Sensor. data (IoT) now is collected via WiFi inside the display.py python script and can be used as needed.
Other IoT services that need registration can be configured for remote data collection via the internet like AWS IoT, ThingSpeak, Azure IoT, Machinechat, Arduino IoT among others. The SparkFun DataLogger IoT - 9DoF is a portable, versatile and easy to use data logger that can be used in many IoT applications.
This article is available in spanish language here
Este artículo está disponible en idioma español aquí.



