Using LoRa communication, string_buf of LoRa client has the following data.
string_buf has data: 23.5, 88, 1002, 12500
But when I compile my sketch, I got an error message like “ 'class String' has no member named 'readBytesUntil' “.
I know that the readBytesUntil function cannot be used because the string_buf of my sketch is not a Stream Class.
I studied the Stream class in the Arduino reference (Stream - Arduino Reference), but I couldn't figure out how to make the string data as a Stream class.
How do I modify my sketch to use the ”readBytesUntil(',', myData[0],20)” function?
#include <RH_RF95.h>
#include <Stream.h>
#define RFM95_INT 18 // "A" // MEGA 18, UNO 2
#define RFM95_CS 53 // "B" // MEGA 53, UNO 10
#define RFM95_RST 40 // "C" // MEGA assigned 40(임의로 변경 가능), uno 9(Module의 reset pin과 연결)
#define RF95_FREQ 915.0
RH_RF95 rf95(RFM95_CS, RFM95_INT);
int LED = 9;
int i = 0;
char myData[4][20] = {0};
char string_buf[4][5] = {0};
void setup() {
Serial.begin(9600);
while (!Serial) {
// while (!Serial) ; // Wait for serial port to be available
delay(1);
}
delay(100);
Serial.println("RX Serial ok");
if (!rf95.init())
Serial.println("rf95_RX init failed");
else
Serial.println("rf95_RX init OK");
// rf95_serial.begin(9600);
// Serial.println(rf95_serial.available());
}
void loop() {
Serial.println("Receiving Data from Server");
char buf[RH_RF95_MAX_MESSAGE_LEN];
//uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
String buf_String[RH_RF95_MAX_MESSAGE_LEN];
if (rf95.waitAvailableTimeout(4000))
{
// Should be a reply message for us now
if (rf95.recv(buf, &len))// buf has "23.5,88,1002,12500"received from RF95_TX;
{
RH_RF95::printBuffer("printBuffer_buf_Data,buf,len: ", buf, len);
Serial.print("(char*)buf: ");
Serial.println((char*)buf);
String string_buf = (char*)buf;
Serial.print("String string_buf=(char*)buf: ");
Serial.println(string_buf);
// string_buf has data : "23.5,88,1002,12500"
string_buf.readBytesUntil(',', myData[0], 20);
{
float X1 = atof(myData[0]);
//Serial.println(X1,1);
//int X2 = atoi(myData[1]);
//Serial.println(X2);
//int X3 = atoi(myData[2]);
//Serial.println(X3);
//int X4 = atoi(myData[3]);
//Serial.println(X4);
digitalWrite(LED, HIGH);
Serial.print("RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
}
delay(100);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf95_server running?");
}
delay(400);
}
To: johnwasser
Thank you very much.
Editing my sketch as you recommended, I have solved the problem I had been struggling with it for about 2 weeks.
A part of the modified code is like the capture picture below.