Hi there!
I actually am trying to develop a sensing system for a personal project of mine.
I am attempting to use the ENV and LoRa modules to achieve this.
So far, I have been able to get the data from the ENV unit sent over LoRa, and I would like to upload said data over to thingspeak, however, I've been getting a very slow response on my M5, either that or the data that is uploaded is not the same.
Do excuse me for the lack of information on the post as I can barely keep my eyes open.
Here are the codes for the Sending end of the LoRa M5 :
#include <M5Stack.h>
#include <M5LoRa.h>
#include "DHT12.h"
#include <Wire.h>
#include "Adafruit_Sensor.h"
#include <Adafruit_BMP280.h>
DHT12 dht12; //Preset scale CELSIUS and ID 0x5c.
Adafruit_BMP280 bme;
void setup() {
M5.begin();
M5.Power.begin();
Wire.begin();
M5.Lcd.setBrightness(20);
Serial.println(F("ENV Unit(DHT12 and BMP280) test..."));
while (!bme.begin(0x76)){
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
M5.Lcd.println("Could not find a valid BMP280 sensor, check wiring!");
}
M5.Lcd.clear(BLACK);
M5.Lcd.println("ENV Unit test...");
Serial.begin(115200); //Initialize serial
// override the default CS, reset, and IRQ pins (optional)
LoRa.setPins(); // default set CS, reset, IRQ pin
Serial.println("LoRa Sender");
M5.Lcd.println("LoRa Sender");
// frequency in Hz (433E6, 866E6, 915E6)
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
M5.Lcd.println("Starting LoRa failed!");
while (1);
}
// LoRa.setSyncWord(0x69);
Serial.println("LoRa init succeeded.");
M5.Lcd.println("LoRa init succeeded.");
}
void loop() {
// try to parse packet
//static uint32_t Temp2 = dht12.readTemperature();
float tmp = dht12.readTemperature();
float hum = dht12.readHumidity();
float pressure = bme.readPressure();
Serial.print("Sending packet: ");
Serial.println(tmp);
// send packet
LoRa.beginPacket();
//LoRa.print("Temperature ");
LoRa.print(tmp);
LoRa.endPacket();
Serial.printf("Temperatura: %2.2f*C Humedad: %0.2f%% Pressure: %0.2fPa\r\n", tmp, hum, pressure);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.printf("Temp: %2.1f \r\nHumi: %2.0f%% \r\nPressure:%2.0fPa\r\n", tmp, hum, pressure);
delay(1000);
}
and here are the codes for Receiving end of the M5 LoRa:
#include <M5Stack.h>
#include <M5LoRa.h>
//#include "ThingSpeak.h"
//#include "secrets.h"
//#include <WiFi.h>
/*char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
int number = 0;
*/
char ch;
void setup() {
M5.begin();
M5.Power.begin();
M5.Lcd.setBrightness(20);
/*WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);*/ // Initialize ThingSpeak
// override the default CS, reset, and IRQ pins (optional)
LoRa.setPins(); // default set CS, reset, IRQ pin
Serial.println("LoRa Receiver");
M5.Lcd.println("LoRa Receiver");
// frequency in Hz (433E6, 866E6, 915E6)
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
M5.Lcd.println("Starting LoRa failed!");
while (1);
}
// LoRa.setSyncWord(0x69);
Serial.println("LoRa init succeeded.");
M5.Lcd.println("LoRa init succeeded.");
}
void loop() {
M5.update();
// Connect or reconnect to WiFi
/*if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.printf("Attempting to connect to SSID: \r\n");
M5.Lcd.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
//delay(5000);
}
Serial.println("\nConnected.");
M5.Lcd.printf("\nConnected.");
M5.Lcd.clear(BLACK);
}*/
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet: \"");
M5.Lcd.print("Received packet: \"");
// read packet
while (LoRa.available()) {
ch = (char)LoRa.read();
Serial.print(ch);
M5.Lcd.print(ch);
}
// print RSSI of packet
Serial.print("\" with RSSI ");
Serial.println(LoRa.packetRssi());
M5.Lcd.print("\" with RSSI ");
M5.Lcd.println(LoRa.packetRssi());
}
/*int x = ThingSpeak.writeField(myChannelNumber, 1, ch, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
delay(10000);
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
delay(10000);
}*/
if (M5.BtnA.wasReleased()) {
M5.Lcd.clear(BLACK);
M5.Lcd.setCursor(0, 0);
}
//delay(20000); // Wait 20 seconds to update the channel again
//delay(1000);
}
Do ask away if you are confused! Thanks in advance for the help.