mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-10 07:10:42 +00:00
Add files via upload
This commit is contained in:
parent
688e74c956
commit
c2a640a1a6
@ -1,5 +1,5 @@
|
||||
|
||||
typedef struct DataReading {
|
||||
typedef struct __attribute__((packed)) DataReading {
|
||||
float d;
|
||||
uint16_t id;
|
||||
uint8_t t;
|
||||
|
@ -32,6 +32,7 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
begin_espnow();
|
||||
#ifdef USE_WIFI
|
||||
delay(10);
|
||||
@ -48,7 +49,9 @@ void setup() {
|
||||
if (!LoRa.begin(BAND)) {
|
||||
while (1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Serial.println(sizeof(DataReading));
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -1,8 +1,8 @@
|
||||
#define UNIT_MAC 0xFD // THIS UNIT
|
||||
#define ESPNOW1_MAC 0xFE // ESPNOW1 Address
|
||||
#define ESPNOW2_MAC 0xFF // ESPNOW2 Address
|
||||
#define LORA1_MAC 0xFE // LoRa1 Address
|
||||
#define LORA2_MAC 0xFF // LoRa2 Address
|
||||
#define ESPNOW1_PEER 0xFE // ESPNOW1 Address
|
||||
#define ESPNOW2_PEER 0xFF // ESPNOW2 Address
|
||||
#define LORA1_PEER 0xFE // LoRa1 Address
|
||||
#define LORA2_PEER 0xFF // LoRa2 Address
|
||||
|
||||
#define ESPNOW1_DELAY 0
|
||||
#define ESPNOW2_DELAY 0
|
||||
|
@ -4,15 +4,15 @@
|
||||
|
||||
#include "defaults.h"
|
||||
|
||||
#define UNIT_MAC 0x01 // THIS UNIT
|
||||
#define UNIT_MAC 0x00 // THIS UNIT
|
||||
|
||||
//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 sendSerial();
|
||||
#define SERIAL_ACT
|
||||
#define MQTT_ACT sendSerial();
|
||||
#define LORAG_ACT sendSerial();
|
||||
#define MQTT_ACT
|
||||
#define LORAG_ACT
|
||||
|
||||
|
||||
//ESP32 Only
|
||||
|
@ -4,11 +4,11 @@ const uint8_t mac_prefix[] = {MAC_PREFIX};
|
||||
|
||||
uint8_t broadcast_mac[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
|
||||
uint8_t ESPNOW1[] = {MAC_PREFIX, ESPNOW1_MAC};
|
||||
uint8_t ESPNOW2[] = {MAC_PREFIX, ESPNOW2_MAC};
|
||||
uint8_t ESPNOW1[] = {MAC_PREFIX, ESPNOW1_PEER};
|
||||
uint8_t ESPNOW2[] = {MAC_PREFIX, ESPNOW2_PEER};
|
||||
uint8_t incMAC[6];
|
||||
uint8_t LoRa1[] = {mac_prefix[4], LORA1_MAC};
|
||||
uint8_t LoRa2[] = {mac_prefix[4], LORA2_MAC};
|
||||
uint8_t LoRa1[] = {mac_prefix[3], mac_prefix[4], LORA1_PEER};
|
||||
uint8_t LoRa2[] = {mac_prefix[3], mac_prefix[4], LORA2_PEER};
|
||||
|
||||
DataReading theData[256];
|
||||
uint8_t ln;
|
||||
@ -117,8 +117,11 @@ void getLoRa() {
|
||||
uint8_t packet[packetSize];
|
||||
uint8_t incLORAMAC[2];
|
||||
LoRa.readBytes((uint8_t *)&packet, packetSize);
|
||||
if (memcmp(&packet, &selfAddress[4], 2) == 0) { //Check if addressed to this device
|
||||
memcpy(&incLORAMAC, &packet[2], 2); //Split off address portion of packet
|
||||
// for (int i = 0; i < packetSize; i++) {
|
||||
// Serial.println(packet[i], HEX);
|
||||
// }
|
||||
if (memcmp(&packet, &selfAddress[3], 3) == 0) { //Check if addressed to this device
|
||||
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
|
||||
else if (memcmp(&incLORAMAC, &LoRa2, 2) == 0) newData = 8;
|
||||
@ -301,8 +304,8 @@ void releaseESPNOW(uint8_t interface) {
|
||||
#ifdef USE_LORA
|
||||
void transmitLoRa(uint8_t* mac, DataReading * packet, uint8_t len) {
|
||||
uint8_t pkt[5 + (len * sizeof(DataReading))];
|
||||
memcpy(&pkt, mac, 2);
|
||||
memcpy(&pkt[2], &selfAddress[4], 2);
|
||||
memcpy(&pkt, mac, 3);
|
||||
memcpy(&pkt[3], &selfAddress[4], 2);
|
||||
memcpy(&pkt[5], packet, len * sizeof(DataReading));
|
||||
LoRa.beginPacket();
|
||||
LoRa.write((uint8_t*)&pkt, sizeof(pkt));
|
||||
|
Loading…
Reference in New Issue
Block a user