Trouble with ThingSpeak Library and M5Stack LoRa

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.

Can you provide a link to the 'M5Stack' you are using ?

Is it an Arduino ?

Sure! This is the link for the exact product I am using at the moment : https://m5stack.com/collections/m5-core/products/m5go-iot-starter-kit-stem-education

It is not an arduino, but it is compatible with the Arduino IDE. It's running on an ESP32 Processor.

Ah well, must be a new product, not heard it mentioned on here before.

Do the company that sell them have a support forum ?

Yes they do.

I'm just widening the net to see if anyone out here could potentially help me out, code wise.

Well you have the hardware, which is causing the problem, the 'sender' or the 'receiver' ?

I am only guessing that the 'sender' and 'receiver' are seperate units ?

Sender and Receiver are separate units indeed.

Receiver is causing the problems.

I believe I was able to identify one of the issue (it could be the main issue).

This section of the code

while (LoRa.available()) {
      ch = (char)LoRa.read();
      Serial.print(ch);
      M5.Lcd.print(ch);
    }

I tried converting the char to float using atof, but I got this error instead : invalid conversion from 'char' to 'const char*' [-fpermissive]

Would be nice if I could get some clarity on that error.