Alıcı olarak Arduino mega üzerine ethernet shield ve loraları bağladık. Ve thingspeak üzerinden veri almaya çalışırken ekteki hatayla karşılaştık.
Verici olarak PCB üzerine arduino nano ve e32 taktık.
ABİ ALICI KODU
#include “LoRa_E32.h”
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A8, A9);
/*
Pinler Arduino Nano Lora E32 433T20d
11 3
10 4
*/
#include <Ethernet.h>
#include “secrets.h”
#include <SPI.h>
#include “ThingSpeak.h” // always include thingspeak header file after other header files and custom macros
byte mac[] = SECRET_MAC;
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 11, 177);
IPAddress myDns(192, 168, 11, 1);
EthernetClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
float sicaklik = 0;
float nem = 0;
LoRa_E32 e32ttl(&mySerial);
struct Signal {
char type[15] = “Fixaj.com”;
byte temp[4];
byte nem[4];
} data;
void setup() {
Serial.begin(9600);
delay(500);
e32ttl.begin();
delay(500);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
Ethernet.init(10);
Serial.println(“Initialize Ethernet with DHCP:”);
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println(“Ethernet shield was not found. Sorry, can’t run without hardware. :(“);
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println(“Ethernet cable is not connected.”);
}
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip, myDns);
} else {
Serial.print(” DHCP assigned IP “);
Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a second to initialize:
delay(1000);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
while (e32ttl.available() > 1) {
ResponseStructContainer rsc = e32ttl.receiveMessage(sizeof(Signal));
struct Signal data = *(Signal*) rsc.data;
Serial.print(“Yer: “);
Serial.println(data.type);
Serial.print(“Ortam Sıcaklığı: “);
Serial.println(*(float*)(data.temp));
Serial.print(“Ortam Nemi: “);
Serial.println(*(float*)(data.nem));
rsc.close();
sicaklik = *(float*)(data.temp);
nem = *(float*)(data.nem);
//UÇMAYA BAŞLIYORUZ..
ThingSpeak.setField(1, sicaklik);
ThingSpeak.setField(2, nem);
// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if (x == 200) {
Serial.println(“Channel update successful.”);
}
else {
Serial.println(“Problem updating channel. HTTP error code ” + String(x));
}
delay(5000);
}
}
VERİCİ KODU:
#include
<Wire.h>
#include
"ClosedCube_HDC1080.h"
ClosedCube_HDC1080 hdc1080;
#include
"LoRa_E32.h"
#include
<SoftwareSerial.h>
SoftwareSerial mySerial(
10
,
11
);
// Arduino RX <-- e32 TX, Arduino TX --> e32 RX
LoRa_E32 e32ttl(
&
mySerial);
struct Signal {
char
type[
15
]
=
"Fixaj.com"
;
byte
temp[
4
];
byte
nem[
4
];
} data;
void
setup
()
{
Serial.begin
(
9600
);
Serial.println
(
"Fixaj.com Arduino Test"
);
// Default settings:
// - Heater off
// - 14 bit Temperature and Humidity Measurement Resolutions
hdc1080.begin(
0x40
);
Serial.print
(
"Manufacturer ID=0x"
);
Serial.println
(hdc1080.readManufacturerId(), HEX);
// 0x5449 ID of Texas Instruments
Serial.print
(
"Device ID=0x"
);
Serial.println
(hdc1080.readDeviceId(), HEX);
// 0x1050 ID of the device
e32ttl.begin();
delay
(
500
);
}
void
loop
()
{
delay
(
3000
);
*
(
float
*
)(data.temp)
=
hdc1080.readTemperature();
*
(
float
*
)(data.nem)
=
hdc1080.readHumidity();
ResponseStatus rs
=
e32ttl.sendFixedMessage(
0
,
63
,
23
,
&
data,
sizeof
(Signal));
Serial.println
(rs.getResponseDescription());
Serial.println
(
*
(
float
*
)(data.temp));
Serial.println
(
*
(
float
*
)(data.nem));
}