mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Node definitions and loraAddress
LoRaAddress[] = {0x42, 0x00}; must not be changed. Therefore it belongs to the default.h proper node definitions for our scenario added
This commit is contained in:
parent
a0de0339a1
commit
dca34a2bfb
@ -5,7 +5,10 @@
|
||||
// Developed by Timm Bogner (bogner1@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
// An example of how to send data using "fdrs_sensor.h".
|
||||
//
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
|
||||
#include <FDRSdefaults.h>
|
||||
#include "fdrs_sensor.h"
|
||||
|
||||
float data1 = 42.069;
|
||||
|
@ -5,9 +5,6 @@
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
|
||||
#include <FDRSdefaults.h>
|
||||
|
||||
#define ROLE LORA_SENSOR
|
||||
@ -75,7 +72,6 @@ typedef struct __attribute__((packed)) DataReading {
|
||||
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
||||
uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC};
|
||||
uint8_t gtwyAddress[] = {gatewayAddress[3], gatewayAddress[4], GTWY_MAC};
|
||||
uint8_t LoRaAddress[] = {0x42, 0x00};
|
||||
|
||||
|
||||
uint32_t wait_time = 0;
|
||||
@ -141,7 +137,7 @@ void beginFDRS() {
|
||||
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
||||
#ifdef USE_LORA
|
||||
uint8_t pkt[5 + (len * sizeof(DataReading))];
|
||||
memcpy(&pkt, mac, 3);
|
||||
memcpy(&pkt, mac, 3); //
|
||||
memcpy(&pkt[3], &LoRaAddress, 2);
|
||||
memcpy(&pkt[5], packet, len * sizeof(DataReading));
|
||||
LoRa.beginPacket();
|
||||
|
@ -21,18 +21,18 @@ void setup() {
|
||||
beginFDRS();
|
||||
}
|
||||
void loop() {
|
||||
data1=readHum();
|
||||
data1 = readHum();
|
||||
loadFDRS(data1, HUMIDITY_T);
|
||||
data2=readTemp();
|
||||
data2 = readTemp();
|
||||
loadFDRS(data2, TEMP_T);
|
||||
sendFDRS();
|
||||
sleepFDRS(10); //Sleep time in seconds
|
||||
}
|
||||
|
||||
float readTemp(){
|
||||
return 42.069;
|
||||
float readTemp() {
|
||||
return 42.069;
|
||||
}
|
||||
|
||||
float readHum(){
|
||||
float readHum() {
|
||||
return 21.0345;
|
||||
}
|
||||
|
@ -4,15 +4,15 @@
|
||||
//
|
||||
// Developed by Timm Bogner (timmbogner@gmail.com) for Sola Gratia Farm in Urbana, Illinois, USA.
|
||||
//
|
||||
#include <FDRSdefaults.h>
|
||||
#define READING_ID 2 //Unique ID for this sensor
|
||||
#define GTWY_MAC 0x00 //Address of the nearest gateway
|
||||
#define GTWY_MAC 0x01 //Address of the nearest gateway
|
||||
|
||||
#define USE_ESPNOW
|
||||
//#define USE_LORA
|
||||
#define DEEP_SLEEP
|
||||
//#define POWER_CTRL 14
|
||||
#define DEBUG
|
||||
#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
//#define MAC_PREFIX 0xAA, 0xBB, 0xCC, 0xDD, 0xEE
|
||||
|
||||
//LoRa Configuration
|
||||
#define SCK 5
|
||||
@ -68,7 +68,6 @@ typedef struct __attribute__((packed)) DataReading {
|
||||
const uint16_t espnow_size = 250 / sizeof(DataReading);
|
||||
uint8_t gatewayAddress[] = {MAC_PREFIX, GTWY_MAC};
|
||||
uint8_t gtwyAddress[] = {gatewayAddress[3], gatewayAddress[4], GTWY_MAC};
|
||||
uint8_t LoRaAddress[] = {0x42, 0x00};
|
||||
|
||||
|
||||
uint32_t wait_time = 0;
|
||||
@ -118,6 +117,8 @@ void beginFDRS() {
|
||||
#endif
|
||||
#ifdef USE_LORA
|
||||
DBG("Initializing LoRa!");
|
||||
DBG(BAND);
|
||||
DBG(SF);
|
||||
#ifndef __AVR__
|
||||
SPI.begin(SCK, MISO, MOSI, SS);
|
||||
#endif
|
||||
@ -125,6 +126,7 @@ void beginFDRS() {
|
||||
if (!LoRa.begin(BAND)) {
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(SF);
|
||||
DBG(" LoRa Initialized.");
|
||||
#endif
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
//
|
||||
// GATEWAY 2.000 Configuration
|
||||
|
||||
// #define UNIT_MAC 0x01 // The address of this gateway
|
||||
#define UNIT_MAC 0x01 // The address of this gateway
|
||||
|
||||
//Actions -- Define what happens when a packet arrives at each interface:
|
||||
//Current function options are: sendESPNOW(MAC), sendSerial(), sendMQTT(), bufferESPNOW(interface), bufferSerial(), and bufferLoRa(interface).
|
||||
|
||||
//#define ESPNOWG_ACT sendESPNOW(0x00);
|
||||
#define ESPNOWG_ACT sendESPNOW(0x00);
|
||||
//#define SERIAL_ACT
|
||||
//#define MQTT_ACT
|
||||
//#define LORAG_ACT
|
||||
|
@ -10,10 +10,10 @@
|
||||
#define DEBUG
|
||||
#define CREDENTIALS
|
||||
|
||||
// #define ESPNOWG_ACT sendSerial();
|
||||
//#define ESPNOWG_ACT sendSerial();
|
||||
// #define SERIAL_ACT
|
||||
// #define MQTT_ACT
|
||||
// #define LORAG_ACT sendSerial();
|
||||
#define LORAG_ACT sendSerial();
|
||||
|
||||
#define USE_LORA
|
||||
//#define USE_WIFI //Used only for MQTT gateway
|
||||
|
@ -131,16 +131,20 @@ void getLoRa() {
|
||||
Serial.println(packet[i], HEX);
|
||||
}
|
||||
if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device
|
||||
DBG("Packet for me");
|
||||
memcpy(&incLORAMAC, &packet[3], 2); //Split off address portion of packet
|
||||
memcpy(&theData, &packet[5], packetSize - 5); //Split off data portion of packet
|
||||
if (memcmp(&incLORAMAC, &LoRa1, 2) == 0) newData = 7; //Check if it is from a registered sender
|
||||
if (memcmp(&incLORAMAC, &LoRa1, 2) == 0) {
|
||||
newData = 7; //Check if it is from a registered sender
|
||||
DBG("From Registred sender");
|
||||
}
|
||||
else if (memcmp(&incLORAMAC, &LoRa2, 2) == 0) newData = 8;
|
||||
else newData = 6;
|
||||
DBG (newData);
|
||||
DBG (newData);
|
||||
ln = (packetSize - 5) / sizeof(DataReading);
|
||||
newData = 6;
|
||||
DBG("Incoming LoRa.");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user