Hi all,
I am working on a section of code that if the incoming LoRa packet includes your ID it will delete your ID!
Error:
cannot convert 'String' to 'const char*' for argument '1' to 'char* strstr(const char*, const char*)'
Code
//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/*DEFINE THE PINS USED BY LORA TRANSCEIVER MODULE*/
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26
/*SET THE CHANNEL AND FREQUENCY OF LORA TRANSCEIVER*/
#define BAND 915E6 //915MHz, E6 channel
/*DEFINE THE PINS USED BY THE OLED SCREEN*/
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST); //WHAT DOES THIS DO?
int myID = +6488436924;
int receivedMessage;
const byte numChars = 85;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
String loraData;
void setup() {
/*INITIALIZE THE SERIAL MONITOR*/
Serial.begin(115200); //set the baud rate to 115200
/*RESET OLED DISPLAY VIA SOFTWARE*/
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);
/*INIALIZE THE OLED DISPLAY*/
Wire.begin(OLED_SDA, OLED_SCL);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32 OLED
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
/*SETUP THE OLED SCREEN AND DISPLAY SOME TEXT*/
display.clearDisplay(); //clear the OLED display
display.setTextColor(WHITE); //Set the text colour to white
display.setTextSize(1); //set the text size
display.setCursor(0, 0); //start at top left of OLED screen
display.print("LORA TRANSCEIVER "); //display title "LORA TRANSCEIVER"
display.display(); //WHAT DOES THIS DO?
/*DEFINE SOME PINS FOR OLED AND LORA MODULE*/
SPI.begin(SCK, MISO, MOSI, SS); //SPI LoRa pins
LoRa.setPins(SS, RST, DIO0); //setup LoRa transceiver module
/*START-UP LORA MODULE?*/
if (!LoRa.begin(BAND)) { //if LoRa does to begin 915E6?
Serial.println("Starting LoRa failed!"); //Serial.print
while (1);
}
/*SET THE LORA MODULES SPREADING FACTOR, SYNC WORD*/
LoRa.setSpreadingFactor(12); //LoRa spreading factor can range from 7 to 12 (Minimize bandwidth and maximize spreading factor to boost link budget. Maximize coding rate to boost reliability)
LoRa.setSyncWord(0x87); // ranges from 0-0xFF, default 0x34, see API docs
/*TELL USER THAT LORA SETUP WAS SUCCESSFUL VIA OLED SCREEN*/
display.setCursor(0, 10); //OLED screen second line far left
display.print("LoRa Initializing OK!"); //display on OLED screen
display.display(); //WHAT DOES THIS DO?
delay(2000);
}
void loop() {
display.clearDisplay(); //clear OLED screen
display.setCursor(0, 0); //start at top left of screen
display.println("LORA TRANSCEIVER"); //display text "LORA TRANSCEIVER"
display.display();
int packetSize = LoRa.parsePacket();
if (packetSize) {
//read packet
while (LoRa.available()) {
loraData = LoRa.readString();
}
//print RSSI of packet
int rssi = LoRa.packetRssi();
Serial.println ("Message Received:");
//Serial.println (LoRaData);
/*If New LoRa Data Has Been Received Send this Data to the phone and Store the Lat and Long Data in Variables*/
if (strstr(loraData, myID)) { //if data received includes my ID
strcpy(receivedMessage, (char *)(strstr(loraData, myID) + 11)); //make variable lat1 = the received data excluding the word "lat"
Serial.print (loraData);
}
// Dsiplay information
display.clearDisplay();
display.setCursor(0, 0);
display.print("MESSAGE RECEIVED");
display.setCursor(0, 20);
display.print(loraData);
display.setCursor(0, 55);
display.print("RSSI:");
display.setCursor(30, 55);
display.print(rssi);
display.display();
delay (5000);
}
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 85) {
Serial.println ("Error: Message Over 85 Characters ");
}
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
LoRa.beginPacket(); //begin the LoRa packet
LoRa.print(receivedChars); //include the variiable "counter"
LoRa.endPacket(); //end and send the LoRa packet
newData = false;
Serial.println ("Message Sent:");
Serial.println (receivedChars);
display.clearDisplay(); //clear OLED screen
display.setCursor(0, 0); //start at top left of screen
display.println("MESSAGE SENT"); //display text "LORA SENDER"
display.setCursor(0, 20); //second line far left of OLED screen
display.setTextSize(1); //set the OLED screen text size
display.print(receivedChars); //display text "LoRa packet sent." on OLED screen
display.display();
delay (5000);
}
}
How might I be able to fix this?
Thanks,
Zeb