Lora connection

parent 47eed182
/* Lora arduino
* Receiver Side Code
*
Module SX1278 // Arduino UNO
Vcc -> 3.3V
MISO -> D12
MOSI -> D11
SLCK -> D13
Nss -> D10
GND -> GND
*/
int myInt;
String str;
#include <SoftwareSerial.h>
SoftwareSerial espSerial(5, 6);
#include <Wire.h>
#include <SPI.h>
#include <LoRa.h>
String abtc,obtc,abtf,afsv,MQ7,MQ2,MQ135,piz,calv,dstd,MQ3,spo2,avBMP;
String inString = ""; // string to hold incoming charaters
String MyMessage = "";
String inStringcom = ""; // string to hold incoming charaters
String MyMessagecom = "";// Holds the complete message
String MyMessagecom1 = "";
void setup() {
espSerial.begin(115200);
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) { // or 915E6
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// read packet
while (LoRa.available())
{
int inChar = LoRa.read();
//////////////////////////////////////////////////////////////////
if(inChar=='\n'){
Serial.println("working on....");
inString = "";
}
if(inChar=='@'){
abtc =inString;
Serial.println("abtc"+abtc);
inString = "";
}
else if(inChar=='#'){
obtc =inString;
Serial.println("obtc"+obtc);
inString = "";
}
else if(inChar=='$'){
abtf =inString;
Serial.println("abtf"+abtf);
inString = "";
}
else if(inChar=='^'){
afsv =inString;
Serial.println("afsv"+afsv);
inString = "";
}
else if(inChar=='&'){
MQ7 =inString;
Serial.println("MQ7"+MQ7);
inString = "";
}
else if(inChar=='*'){
MQ2 =inString;
Serial.println("MQ2"+MQ2);
inString = "";
}
else if(inChar=='_'){
MQ135 =inString;
Serial.println("MQ135"+MQ135);
inString = "";
}
else if(inChar=='<'){
piz =inString;
Serial.println("piz"+piz);
inString = "";
}
else if(inChar=='+'){
calv =inString;
Serial.println("calv"+calv);
inString = "";
}
else if(inChar=='|'){
dstd =inString;
Serial.println("dstd"+dstd);
inString = "";
}
else if(inChar==':'){
MQ3 =inString;
Serial.println("MQ3"+MQ3);
inString = "";
MyMessagecom1="";
MyMessagecom1=MyMessagecom;
MyMessagecom="";
}
else if(inChar=='?'){
spo2 =inString;
Serial.println("spo2"+spo2);
//Serial.println(spo2);
inString = "";
}
else if(inChar=='{'){
avBMP =inString;
Serial.println("avBMP"+avBMP);
inString = "";
}
else if(inChar=='='){
MyMessage="";
inString="";
}
///////////////////////////////////////////////////////////////////
inString += (char)inChar;
MyMessage = inString;
//Serial.println(inString);
//delay(800);
inStringcom += (char)inChar;
MyMessagecom = inStringcom;
//delay(5);
}
LoRa.packetRssi();
///////////////////////////////////////////////////
inString = "";
}
//////////////////////////////////////////////////
////////////////////////////////////////////////
Serial.print(MyMessagecom1);
Serial.println("..............................................");
Serial.println(MyMessagecom);
//Serial.println('\n');
delay(600);
//stringtoint();
////////////////////////////////////////////
/* register request event */
espSerial.println(MyMessagecom);
espSerial.println(MyMessagecom1);
MyMessagecom1="";
MyMessagecom="";
inStringcom="";
Serial.println("loop compleated");
/////////////////////////////////////////////
}
//nodemcu code
#include <LoRa.h>
#include<String.h>
#include<SPI.h>
#include<ESP8266WiFi.h>
#include <Wire.h>
#include "Ubidots.h"
String abtc,obtc,abtf,afsv,MQ7,MQ2,MQ135,piz,calv,dstd,MQ3,spo2,avBMP;
int abtcf,obtcf,abtff,afsvf,MQ7f,MQ2f,MQ135f,pizf,calvf,dstdf,MQ3f,spo2f,avBMPf;
char c;
int x;
String inString = ""; // string to hold incoming charaters
String MyMessage = "";
//WidgetLCD lcd(V1);
//////////////////////////////////////////////////////
const char* UBIDOTS_TOKEN = "BBFF-Rp4KIh5GHSDP487fDpwgWZuBREXLrU"; // Put here your Ubidots TOKEN
const char* WIFI_SSID = "Minosh"; // Put here your Wi-Fi SSID
const char* WIFI_PASS = "minoshsliit12#"; // Put here your Wi-Fi password
Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);
/////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200);
ubidots.wifiConnect(WIFI_SSID, WIFI_PASS);
delay(1000);
}
void loop()
{
readdata();
//ubidots.add("abtc", abtcf);delay(50);
ubidots.add("obtcf", obtcf);delay(50);
//ubidots.add("abtff", abtff);delay(50);
ubidots.add("afsvf", afsvf);delay(50);
ubidots.add("MQ7f", MQ7f);delay(50);
ubidots.add("MQ2f", MQ2f);delay(50);
ubidots.add("pizf", pizf);delay(50);
ubidots.add("calvf", calvf);delay(50);
ubidots.add("dstdf", dstdf);delay(50);
ubidots.add("MQ3f", MQ3f);delay(50);
ubidots.add("spo2f", spo2f);delay(50);
ubidots.add("avBMPf", avBMPf);delay(50);
bool bufferSent = false;
bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id
if (bufferSent) {
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
delay(1000);
}
void readdata(){
//delay(1000);
while (Serial.available()) {
//Serial.write(Serial.read());
int p=Serial.read();
if(p=='\n'){
//Serial.println("working on....");
inString = "";
}
if(p=='@'){
abtc =inString;
Serial.println("abtc"+abtc);
inString = "";
}
else if(p=='#'){
obtc =inString;
Serial.println("obtc"+obtc);
inString = "";
}
else if(p=='$'){
abtf =inString;
Serial.println("abtf"+abtf);
inString = "";
}
else if(p=='^'){
afsv =inString;
Serial.println("afsv"+afsv);
inString = "";
}
else if(p=='&'){
MQ7 =inString;
Serial.println("MQ7"+MQ7);
inString = "";
}
else if(p=='*'){
MQ2 =inString;
Serial.println("MQ2"+MQ2);
inString = "";
}
else if(p=='_'){
MQ135 =inString;
Serial.println("MQ135"+MQ135);
inString = "";
}
else if(p=='<'){
piz =inString;
Serial.println("piz"+piz);
inString = "";
}
else if(p=='+'){
calv =inString;
Serial.println("calv"+calv);
inString = "";
}
else if(p=='|'){
dstd =inString;
Serial.println("dstd"+dstd);
inString = "";
}
else if(p==':'){
MQ3 =inString;
Serial.println("MQ3"+MQ3);
inString = "";
}
else if(p=='?'){
spo2 =inString;
Serial.println("spo2"+spo2);
inString = "";
}
else if(p=='{'){
avBMP =inString;
Serial.println("avBMP"+avBMP);
inString = "";
}
else if(p=='='){
MyMessage="";
inString="";
}
delay(10);
inString += (char)p;
MyMessage = inString;
//Serial.println(MyMessage);
abtcf=abtc.toInt();
obtcf=obtc.toInt();
abtff=abtf.toInt();
afsvf=afsv.toInt();
MQ7f=MQ7.toInt();
MQ2f=MQ2.toInt();
MQ135f=MQ135.toInt();
pizf=piz.toInt();
calvf=calv.toInt();
dstdf=dstd.toInt();
MQ3f=MQ3.toInt();
spo2f=spo2.toInt();
avBMPf=avBMP.toInt();
}
inString="";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment