Skip to content

Instantly share code, notes, and snippets.

@YongHuax
Created February 10, 2018 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YongHuax/4e9cdea37d55f8251da55e91a4f88701 to your computer and use it in GitHub Desktop.
Save YongHuax/4e9cdea37d55f8251da55e91a4f88701 to your computer and use it in GitHub Desktop.
LG01-P Send data from ESP32 LoRa to AWSIot
#include <SPI.h>
#include <LoRa.h>
#include <Console.h>
#include <Process.h>
#define PABOOST true
#define BAND 433E6
void uploadData();
void setup() {
Bridge.begin(115200);
Console.begin();
// while (!Console);
Console.println("LoRa Receiver to Mqtt");
if (!LoRa.begin(BAND)) {
Console.println("Starting LoRa failed!");
while (1);
}
LoRa.setSpreadingFactor(9);
}
void loop() {
//initialize Linux Message parameters
int pc = 0; //packetcounter
String message ;
String message2 ;
char lorainput ;
// Set all values in Linux Message to 0
// int pc2 = 0 ;
// try to parse packet
int packetSize = LoRa.parsePacket(); // Supposed to be 4
if (packetSize) {
// received a packet
Console.println("Received packet '");
Console.print("Packet Size = ");
Console.println(packetSize);
// read packet
for( int i = 0 ; i<packetSize;i++){
lorainput = (char)LoRa.read();
message = message + lorainput;
//Console.print(messages[i]);
}
Console.print(" message received " );
Console.println(message);
Console.print("' with RSSI ");
Console.println(LoRa.packetRssi());
String tempstorage = message ;
//String tempstorage2 = "" ;
// uploadData(tempstorage,tempstorage2);
uploadData(tempstorage);
}
}
void uploadData(String uploaddata1) {//Upload Data to ThingSpeak
// void uploadData(String uploaddata1,String uploaddata2)
Console.println("Call Linux Command to Send Data");
Process p; // Create a process and call it "p", this process will execute a Linux curl command
String upload_url = uploaddata1;
// String upload_url2 = uploaddata2;
p.begin("/root/testAWS"); //Script execution.In this example I use the script name is Test.
p.addParameter(upload_url);
//p.addParameter(upload_url2);
p.run();
//Console.print("Feedback from Linux: ");
// If there's output from Linux,
// send it out the Console:
while (p.available()>0)
{
char c = p.read();
Console.write(c);
}
Console.println("AWS");
Console.println("Call Finished");
Console.println("####################################");
Console.println("");
delay(10000) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment