Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test lora example #15

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/SGP30_demo_lora/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -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
107 changes: 107 additions & 0 deletions examples/SGP30_demo_lora/SGP30_demo_lora.ino
Original file line number Diff line number Diff line change
@@ -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 <SPI.h>
#include <LoRa.h>
#include <SGP30.h>
#include <ArduinoJson.h>
#include <Wire.h>


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 --
Loading