Hey guys,
I’m currently using the RadioHead library with a LoRa shield stacked on a 3G shield (stacked on the arduino, obviously). Now, I can get each shield working separately but when I make a sketch to get data over LoRa and then send it over 3G to ThingSpeak, it does not work. It is either I initialize the 3G shield second and the LoRa shield does not communicate with the client, or I initialize the LoRa shield second and the 3G shield disconnects from the network. Does anyone have any ideas? I have tried changing my program, looking into the library, but RadioHead is pretty complicated and I don’t see where it may be getting in the way. My code:
/*-------------------------INCLUDES-----------------------------*/
#include <SoftwareSerial.h>
#include <SPI.h>
#include "Adafruit_FONA.h"
#include "RHReliableDatagram.h"
#include "RH_RF95.h"
/*----------------------DEFINITIONS-----------------------------*/
#define FONA_TX 4
#define FONA_RX 5
#define FONA_RST 9
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
/*-------------------------GLOBALS------------------------------*/
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
/*----------------------3G CONSTRUCTORS-------------------------*/
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX,FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
/*---------------------LORA CONSTRUCTORS------------------------*/
RH_RF95 driver;
RHReliableDatagram LORAmanager(driver, SERVER_ADDRESS);
/*---------------------------SETUP------------------------------*/
void setup() {
while(!Serial);
Serial.begin(9600);
if (!LORAmanager.init()){
Serial.println("init failed");
} else {
Serial.println("init succeeded");
}
FONAsetup();
}
void FONAsetup() {
int i;
Serial.println(F("FONA basic test"));
Serial.println(F("Initializing..."));
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while (1);
}
Serial.println(F("FONA is OK"));
Serial.print(F("Found"));
fona.setGPRSNetworkSettings(F("pda.bell.ca"));
fona.setHTTPSRedirect(true);
delay(3000);
for(i=0;i<3 && !fona.sendCheckReply(F("AT+CHTTPSSTART"), F("OK"), 10000);i++);
}
void FONASendHTTP() {
int i=0;
char getstr[100] = {0};
char getstr1[] = "GET /update?api_key=2TQ3N7QCJFJXF7KM&field2=";
char getstr2[] = " HTTP/1.1\r\nHost: api.thingspeak.com\r\n\r\n";
strcat(getstr, getstr1);
strcat(getstr, (char*)buf);
strcat(getstr, getstr2);
for(i=0;i<3 && !fona.sendCheckReply(F("AT+CHTTPSOPSE=\"api.thingspeak.com\",443,2"), F("OK") ,10000);i++);
for(i=0;i<3 && !fona.sendCheckReply(F("AT+CHTTPSSEND=120"),F(">"), 10000);i++);
for(i=0;i<3 && !fona.sendCheckReply(getstr, F("OK"), 10000);i++);
for(i=0;i<3 && !fona.sendCheckReply(F("AT+CHTTPSCLSE"),F("OK"),10000);i++);
}
void loop() {
Serial.println("Check if LoRa received");
if(LORAmanager.available()) {
uint8_t len = sizeof(buf);
uint8_t from;
if (LORAmanager.recvfromAck(buf, &len, &from))
{
Serial.print("Got data: ");
Serial.println((char*)buf);
Serial.println("Intiating HTTP request: ");
FONASendHTTP();
}
}
delay(20000);
}