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İ MESAJDAN GÖRÜSMÜSTÜK KOD SİTEDEKİ İLE AYNI
#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, 44, 177);
IPAddress myDns(192, 168, 0, 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(20000);
}
}