Commit bd3b45ff authored by Nelso Jost's avatar Nelso Jost

DEV: litte refactor around meterolog callback

parent 15d2d069
EMM Data Logger
# Meteorolog
This applications retrieves meteorological data from Arduino boards of the project EMM, save them locally and also sent them to a remote server.
This repository contains several applications devoted to perform data logging of sensor data from the EMM boards.
More details on the wiki:
First, sensors are attached to an Arduino board that read data upon serial commands. Next you can choose one of two platforms to perform data logging:
The root directory of this repo contains a Makefile with several commands for easy installation and usage of the software. Make sure to be on this directory when executing commands `make <target>`.
* NodeMCU + SD card: microcontroller with embedded Wifi.
* Arduino firmware: read sensor data via serial commands.
The following topics describe the order of the tasks needed to install and use the software along with the Arduino board.
* Example: send the string "read,t,p,h" for reading temperature, pressure and humidty. The answer will be a three comma-separated numbers.
* NodeMCU firmware: retrieve sensor data from Arduino via software serial and perform data logging on SD card and remote server.
* 1 -- Install system dependencies and prepare local Python execution environment:
* Example: via serial monitor, execute the command "meteorolog 5 read,t,p,h <board_hash>" to start data logging with 5 minutes interval.
<board_hash> can be retrieved from the website
$ make setup
* Python Datalogger: read Arduino data via serial port and perform datalogging locally on the computer HD and also send data to the server.
PS: Uses apt for Debian packages and Python's pip3 will be installed if not present.
* 2 -- Install firmware on the Arduino board via Arduino IDE or the terminal (through Ino Tool) with:
$ make firmware
PS: Stil requires Arduino IDE to be installed.
* 3 -- Test the firmware by sending commands (strings) to the serial port via Arduino IDE Serial Monitor or a Python session on the terminal with:
$ make serial
Refer to the documentation for all available commands:
* 4 -- Prepare the file `settings.ini` with desired behavior and required fields, such as `BOARD_HASH`.
* 5 -- Test the logger execution on the foreground with:
$ make run
Data will be saved on the `data/` subdirectory.
* 6 -- Install the logger for background execution and automatic initiation:
$ make deploy
* 7 -- You can monitor the last generated data or log with:|
$ make tail-log
$ make tail-data
......@@ -16,6 +16,7 @@
#include "repl_wifi.h"
#define BAUDRATE 115200
#define DATALOG_FILENAME "datalog.txt"
#define PIN_LED D3
#define PIN_BUTTON D0
......@@ -34,10 +35,12 @@ typedef struct
REPL * repl;
float interval;
String command;
String board_hash;
void meteorolog_callback(METEOROLOG_args * args);
void sd_datalog(String datalog, REPL * repl);
void server_datalog(String datalog, REPL * repl);
REPL_COMMAND commands[] =\
......@@ -117,6 +120,7 @@ void REPL_METEOROLOG(REPL * repl)
METEOROLOG_args * args = new METEOROLOG_args;
args->interval = repl->get_arg(1).toFloat();
args->command = repl->get_arg(2);
args->board_hash = repl->get_arg(3);
args->repl = repl;
if (args->interval == 0)
......@@ -135,12 +139,34 @@ void REPL_METEOROLOG(REPL * repl)
void meteorolog_callback(METEOROLOG_args * args)
args->repl->log("\n[INFO] Performing datalog..");
args->repl->log("\n[INFO] Sent command '" + args->command + "' to arduino.");
String response="";
while (arduinoSerial.available()) { response +=; }
args->repl->log("\n[INFO] Got response: '" + response + "'");
if (response.length() > 0)
sd_datalog(response, args->repl);
// server_datalog(response, args->repl);
args->repl->log("\n[ERROR] Empty datalog response");
void sd_datalog(String datalog, REPL * repl)
Sd2Card sd_card;
SdVolume sd_volume;
REPL * repl = args->repl;
//repl->log("\n[INFO] Performing datalog..");
if (!sd_card.init(SPI_HALF_SPEED, chipSelect))
......@@ -153,33 +179,24 @@ void meteorolog_callback(METEOROLOG_args * args)
File sd_file ="datalog.txt", FILE_WRITE);
File sd_file =, FILE_WRITE);
if (!sd_file)
repl->log("\n[ERROR] Unable to open 'datalog.txt' for write.");
repl->log("\n[ERROR] Unable to open '" + String(DATALOG_FILENAME) + "'");
String arduino_response;
repl->log("\n[INFO] Sent command '" + args->command + "' to arduino.");
while (arduinoSerial.available())
arduino_response +=;
repl->log("\n[INFO] Got response: '" + arduino_response + "'");
if (arduino_response.length() > 0)
int written = sd_file.println(datalog);
repl->log("\n[INFO] Written at 'datalog.txt'");
repl->log("\n[ERROR] Nothing to write on the sd card.");
repl->log("\n[INFO] " + String(written) + " bytes written at '" +
String(DATALOG_FILENAME) + "'");
void server_datalog(String datalog, REPL * repl)
String response = String("POST emm/api/post/rawsensordata HTTP/1.1\r\n") + \
"Host:" + \
"Content-type: Application/JSON";
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment