From e1d05dfeb548b5f08d1eb5905f095a4def3911cc Mon Sep 17 00:00:00 2001 From: louisa Date: Thu, 11 May 2023 16:20:06 +0200 Subject: [PATCH] Update 'arduino/LoRareceiver/nfcLora.ino' --- .../{sketch_may11a.ino => nfcLora.ino} | 200 +++++++++--------- 1 file changed, 100 insertions(+), 100 deletions(-) rename arduino/LoRareceiver/{sketch_may11a.ino => nfcLora.ino} (95%) diff --git a/arduino/LoRareceiver/sketch_may11a.ino b/arduino/LoRareceiver/nfcLora.ino similarity index 95% rename from arduino/LoRareceiver/sketch_may11a.ino rename to arduino/LoRareceiver/nfcLora.ino index 0b7d8b6..64bde45 100644 --- a/arduino/LoRareceiver/sketch_may11a.ino +++ b/arduino/LoRareceiver/nfcLora.ino @@ -1,100 +1,100 @@ -#include -#include -#include "boards.h" -#include -#include -#include - -PN532_I2C pn532_i2c(Wire); -NfcAdapter nfc = NfcAdapter(pn532_i2c); -String tagId = "None"; -String cleanString = ""; - - -void setup() -{ - Serial.begin(9600); - Serial.println("System initialized"); - nfc.begin(); - - initLoRa(); -} - -void loop() -{ - readNFC(); - if (!cleanString.isEmpty()) { - sendLoRaData(cleanString); - } -} - -void initLoRa() -{ - Serial.println("Initializing LoRa..."); - LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DI0_PIN); - if (!LoRa.begin(LoRa_frequency)) - { - Serial.println("Starting LoRa failed!"); - while (1); - } - Serial.println("LoRa initialized successfully!"); -} - -void sendLoRaData(String data) -{ - String message = "node3 " + data; // Concatenate "node3 " with the value of cleanString - - LoRa.beginPacket(); - LoRa.print(message); - LoRa.endPacket(); -} - -void readNFC() -{ - if (nfc.tagPresent()) - { - NfcTag tag = nfc.read(); - tagId = tag.getUidString(); - Serial.print("Tag ID: "); - Serial.println(tagId); - - if (tag.hasNdefMessage()) - { - NdefMessage message = tag.getNdefMessage(); - int recordCount = message.getRecordCount(); - Serial.print("Number of NDEF records: "); - Serial.println(recordCount); - - for (int i = 0; i < recordCount; i++) - { - NdefRecord record = message.getRecord(i); - int payloadLength = record.getPayloadLength(); - byte payload[payloadLength]; - record.getPayload(payload); - - String payloadAsString = ""; - for (int c = 0; c < payloadLength; c++) - { - payloadAsString += (char)payload[c]; - } - - cleanString = payloadAsString; - cleanString.remove(0, 3); - Serial.print("Payload: "); - Serial.println(cleanString); - - String uid = record.getId(); - if (uid != "") - { - Serial.print("Record ID: "); - Serial.println(uid); - } - } - } - else - { - Serial.println("No NDEF message found on the tag."); - } - delay(2000); - } -} +#include +#include +#include "boards.h" +#include +#include +#include + +PN532_I2C pn532_i2c(Wire); +NfcAdapter nfc = NfcAdapter(pn532_i2c); +String tagId = "None"; +String cleanString = ""; + + +void setup() +{ + Serial.begin(9600); + Serial.println("System initialized"); + nfc.begin(); + + initLoRa(); +} + +void loop() +{ + readNFC(); + if (!cleanString.isEmpty()) { + sendLoRaData(cleanString); + } +} + +void initLoRa() +{ + Serial.println("Initializing LoRa..."); + LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DI0_PIN); + if (!LoRa.begin(LoRa_frequency)) + { + Serial.println("Starting LoRa failed!"); + while (1); + } + Serial.println("LoRa initialized successfully!"); +} + +void sendLoRaData(String data) +{ + String message = "node3 " + data; // Concatenate "node3 " with the value of cleanString + + LoRa.beginPacket(); + LoRa.print(message); + LoRa.endPacket(); +} + +void readNFC() +{ + if (nfc.tagPresent()) + { + NfcTag tag = nfc.read(); + tagId = tag.getUidString(); + Serial.print("Tag ID: "); + Serial.println(tagId); + + if (tag.hasNdefMessage()) + { + NdefMessage message = tag.getNdefMessage(); + int recordCount = message.getRecordCount(); + Serial.print("Number of NDEF records: "); + Serial.println(recordCount); + + for (int i = 0; i < recordCount; i++) + { + NdefRecord record = message.getRecord(i); + int payloadLength = record.getPayloadLength(); + byte payload[payloadLength]; + record.getPayload(payload); + + String payloadAsString = ""; + for (int c = 0; c < payloadLength; c++) + { + payloadAsString += (char)payload[c]; + } + + cleanString = payloadAsString; + cleanString.remove(0, 3); + Serial.print("Payload: "); + Serial.println(cleanString); + + String uid = record.getId(); + if (uid != "") + { + Serial.print("Record ID: "); + Serial.println(uid); + } + } + } + else + { + Serial.println("No NDEF message found on the tag."); + } + delay(2000); + } +}