I am using two t-beams one of which acts as a transmitter connected to a DS18B20 temperature probe and the other t-beam acting as a receiver. now I have used the IDE software to configure both the devices. however the sender and receiver is just able to communicate with each other, the sender says packets sent, the receiver says packets received but the receiver is just not displaying the temperature data or any data per say. I had tested the Lora example code for sender and receiver (to send "Hello world") but that too doesn't work I'm just very unsure why the example code isn't functioning too. please help.
here's the sender code I'm using
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LoRa.h>
#include <SPI.h>
// Pin definitions for LoRa module
#define LORA_SS 18
#define LORA_RST 23
#define LORA_DIO0 26
// Pin definition for DS18B20
#define ONE_WIRE_BUS 22
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(115200);
Serial.println("LoRa Sender");
sensors.begin();
// Setup LoRa transceiver module
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
LoRa.setSPIFrequency(1E6);
Serial.println("Initializing LoRa...");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setTxPower(17);
LoRa.setSpreadingFactor(12);
LoRa.setCodingRate4(8);
LoRa.setSignalBandwidth(250E3);
LoRa.setSpreadingFactor(12); // Adjust spreading factor as needed
LoRa.setSignalBandwidth(125E3); // Adjust bandwidth as needed
Serial.println("LoRa initialized successfully!");
}
void loop() {
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
Serial.print("Preparing to send temperature: ");
Serial.println(temperatureC);
char tempBuffer[10]; // Buffer for temperature string
dtostrf(temperatureC, 4, 2, tempBuffer); // Convert float to string
// Send temperature over LoRa
LoRa.beginPacket();
LoRa.print("TEMP:"); // Add a prefix for data identification
LoRa.print(tempBuffer);
if (LoRa.endPacket(true)) {
Serial.println("Packet sent successfully!");
} else {
Serial.println("Packet send failed.");
}
delay(1000);
}
The receiver code is as follows:
#include <LoRa.h>
#include <SPI.h>
// LoRa module pin definitions
#define LORA_SS 18
#define LORA_RST 23
#define LORA_DIO0 26
void setup() {
Serial.begin(115200);
Serial.println("LoRa Receiver");
// Setup LoRa transceiver module
LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
LoRa.setSPIFrequency(1E6);
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setTxPower(17);
LoRa.setSpreadingFactor(12);
LoRa.setCodingRate4(8);
LoRa.setSignalBandwidth(250E3);
Serial.println("LoRa initialized successfully!");
}
void loop() {
Serial.println("Checking for packets...");
int packetSize = LoRa.parsePacket(5000); // Increase the timeout
if (packetSize) {
Serial.print("Received packet with size: ");
Serial.println(packetSize);
String received = "";
while (LoRa.available()) {
received += (char)LoRa.read();
}
Serial.print("Temperature data received: ");
Serial.println(received);
} else {
Serial.println("No packet received.");
}
delay(1000); // Check for packets every 1 second
}
in this picture sometimes after a point I get the data but the data is a garbage data, as in nothing shows up
I would also like to say that I have not just used Arduino IDE ive also used Platform IO and the Meshtastic app as well, however the data doesn't show up there either
Use code tags to format code for the forum(temperature details)