From 94b7e5adcde05f29fa7766afae8f2404f388ea31 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Fri, 29 Dec 2023 19:24:11 +0100 Subject: [PATCH] test lora example --- examples/SGP30_demo_lora/.arduino-ci.yml | 30 ++++++ examples/SGP30_demo_lora/SGP30_demo_lora.ino | 107 +++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 examples/SGP30_demo_lora/.arduino-ci.yml create mode 100644 examples/SGP30_demo_lora/SGP30_demo_lora.ino diff --git a/examples/SGP30_demo_lora/.arduino-ci.yml b/examples/SGP30_demo_lora/.arduino-ci.yml new file mode 100644 index 0000000..a9686ac --- /dev/null +++ b/examples/SGP30_demo_lora/.arduino-ci.yml @@ -0,0 +1,30 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + # - uno + # - due + # - zero + # - leonardo + # - m4 + - esp32 + # - esp8266 + # - mega2560 + # - rpipico + libraries: + - ArduinoJson + - LoRa diff --git a/examples/SGP30_demo_lora/SGP30_demo_lora.ino b/examples/SGP30_demo_lora/SGP30_demo_lora.ino new file mode 100644 index 0000000..2b15220 --- /dev/null +++ b/examples/SGP30_demo_lora/SGP30_demo_lora.ino @@ -0,0 +1,107 @@ + +// +// FILE: SGP30_demo_lora.ino +// AUTHOR: Rob Tillaart, Anthony Powell +// PURPOSE: demo SGP30 to LORA +// URL: https://github.com/RobTillaart/SGP30 + + +#include +#include +#include +#include +#include + + +SGP30 sgp; + +// Create a unique ID for the data from each ESP32 running this code + +const char* jediID = "Envirodrone"; + +uint32_t lastTime = 0; + +void setup() +{ + Serial.begin(9600); + Serial.println(F("LoRa Sender")); + + if (!LoRa.begin(868E6)) + { + Serial.println("Error: Starting LoRa failed! reboot system"); + while (1); + } + Serial.println(F("Enviro Drone SGP30 Sensor Start")); + delay(1000); + + // Initialize I2C bus + + Wire.begin(); + Wire.setClock(400000); + + // Initialize sensor + while (! sgp.begin()) + { + Serial.println(F("Error: Could not detect SGP30 sensor")); + delay(3000); + } +} + + +void loop() +{ + String postData; + + // send data once every 10 seconds + if (millis() - lastTime >= 10000) + { + uint32_t start = millis(); + Serial.print("time: \t"); + Serial.println(start); + + + Serial.print(millis() - start); + Serial.println("Read SGP30 sensor."); + sgp.measure(true); + float co2 = sgp.getCO2(); + float tvoc = sgp.getTVOC(); + float h2 = sgp.getH2(); + float etha = sgp.getEthanol(); + Serial.print(co2); + Serial.print("\t"); + Serial.print(tvoc); + Serial.print("\t"); + Serial.print(h2); + Serial.print("\t"); + Serial.print(etha); + Serial.println(); + + + Serial.print(millis() - start); + Serial.println("Create serialized JSON string."); + StaticJsonDocument <200> doc; + JsonObject data = doc.createNestedObject("data"); + data["CO2"] = co2; + data["TVOC"] = tvoc; + data["H2"] = h2; + data["Ethanol"] = etha; + serializeJson(doc, postData); + Serial.println(postData); + + + Serial.print(millis() - start); + Serial.println("Send LORA packet."); + LoRa.beginPacket(); + LoRa.print(postData); + LoRa.endPacket(); + + + uint32_t stop = millis(); + Serial.print(millis() - start); + Serial.print("Duration:\t"); + Serial.println(stop - start); + } + + +} +// -- END OF FILE --