From 1d1b20e5c32a8597c751f30ec2f8774c01c34c97 Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 17 Jul 2023 17:09:50 +0200 Subject: [PATCH] add SD support for capteur --- IOT/Capteur/.vscode/settings.json | 11 ++++++- IOT/Capteur/config.ini | 6 +++- IOT/Capteur/src/main.cpp | 52 +++++++++++++++++++++---------- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/IOT/Capteur/.vscode/settings.json b/IOT/Capteur/.vscode/settings.json index d01027a..19b7dc3 100644 --- a/IOT/Capteur/.vscode/settings.json +++ b/IOT/Capteur/.vscode/settings.json @@ -1,6 +1,15 @@ { "files.associations": { "*.html": "html", - "cmath": "cpp" + "cmath": "cpp", + "array": "cpp", + "deque": "cpp", + "list": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "string_view": "cpp", + "initializer_list": "cpp", + "ranges": "cpp" } } \ No newline at end of file diff --git a/IOT/Capteur/config.ini b/IOT/Capteur/config.ini index 8a78241..6fa26b2 100644 --- a/IOT/Capteur/config.ini +++ b/IOT/Capteur/config.ini @@ -65,4 +65,8 @@ build_flags = -D LORA_SPI_MISO=G_MISO -D LORA_SPI_MOSI=G_MOSI - -D LORA_FREQUENCY=433 \ No newline at end of file + -D LORA_FREQUENCY=433 + + -D USE_SD_LOG + -D SD_SS=SD_CS + -D LOG_FILENAME=\"log_capteur_01.txt\" \ No newline at end of file diff --git a/IOT/Capteur/src/main.cpp b/IOT/Capteur/src/main.cpp index 840ade5..967dae4 100644 --- a/IOT/Capteur/src/main.cpp +++ b/IOT/Capteur/src/main.cpp @@ -2,17 +2,9 @@ // #include #include #include -// FARM DATA RELAY SYSTEM -// -// LoRa Sensor Example -// -// Developed by Timm Bogner (timmbogner@gmail.com) in Urbana, Illinois, USA. -// An example of how to send data via LoRa using FDRS. -// - -// #include "fdrs_node_config.h" #include #include +#include float readTemp() { return 21.0; @@ -28,13 +20,41 @@ float data1; float data2; void setup() { - beginFDRS(); + beginFDRS(); + if (!SD.begin(SD_CS)) { + Serial.println("Fail, verifier que la carte SD est presente."); + return; + } } + void loop() { - data1 = readHum(); - loadFDRS(data1, HUMIDITY_T); - data2 = readTemp(); - loadFDRS(data2, TEMP_T); - sendFDRS(); - sleepFDRS(10); //Sleep time in seconds + data1 = readHum(); + loadFDRS(data1, HUMIDITY_T); + data2 = readTemp(); + loadFDRS(data2, TEMP_T); + sendFDRS(); + + File dataFile = SD.open(LOG_FILENAME, FILE_WRITE); + if (dataFile) { + DBG("SD OK"); + dataFile.print("[{\"id\":"); + dataFile.print(READING_ID); + dataFile.print(",\"type\":"); + dataFile.print(HUMIDITY_T); + dataFile.print(",\"data\":"); + dataFile.print(data1); + dataFile.print("},{\"id\":"); + dataFile.print(READING_ID); + dataFile.print(",\"type\":"); + dataFile.print(TEMP_T); + dataFile.print(",\"data\":"); + dataFile.print(data2); + dataFile.println("}]"); + dataFile.close(); + }else{ + DBG("SD fail"); + } + + // [{"id":2,"type":3,"data":66},{"id":2,"type":1,"data":21}] + sleepFDRS(10); //Sleep time in seconds }