Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <LoRa.h>
- const int OK_code = 0xFF;
- const int Write_code = 0xAC;
- int32_t addr = 0;
- float val = 325.87;
- int send_step = 10950;
- typedef union union4byte_t {
- uint8_t Bytes[4];
- int32_t Int;
- int16_t SmalInt[2];
- float Float;
- };
- union4byte_t BufferUnion;
- const size_t BufferSize = 8;
- uint8_t Buffer[BufferSize];
- void Reciever() {
- // try to parse packet
- int packetSize = LoRa.parsePacket();
- if (packetSize) {
- Serial.print(" recieved packet: ");
- while (LoRa.available()) {
- for (size_t i = 0; i < BufferSize; ++i) {
- Buffer[i] = LoRa.read();
- }
- Serial.write(Buffer, BufferSize);
- }
- Serial.println();
- //Send();
- }
- }
- void Send() {
- LoRa.setTxPower(20);
- //Serial.print("Sending answer ");
- for (int i = 0; i < 10; i++) {
- BufferUnion.SmalInt[0] = OK_code;
- BufferUnion.SmalInt[1] = send_step;
- Buffer[4] = BufferUnion.Bytes[0];
- Buffer[5] = BufferUnion.Bytes[1];
- Buffer[6] = BufferUnion.Bytes[2];
- Buffer[7] = BufferUnion.Bytes[3];//*/
- LoRa.beginPacket();
- LoRa.write(Buffer, BufferSize);
- LoRa.endPacket();
- delay(1);
- }
- //Serial.println(" Answer sended");
- }
- void setup() {
- Serial.begin(9600);
- while (!Serial);
- if (!LoRa.begin(430E6)) {
- Serial.println("Starting LoRa failed!");
- while (1);
- }
- Serial.println("LoRa кусшумук starting");
- LoRa.enableCrc();
- }
- void loop() {
- int packetSize = LoRa.parsePacket();
- if (packetSize == 8) {
- //Serial.print(" recieved packet: ");
- while (LoRa.available()) {
- for (size_t i = 0; i < BufferSize; ++i) {
- Buffer[i] = LoRa.read();
- }
- Serial.write(Buffer, BufferSize);
- }
- //Serial.println();
- Send();
- }
- }
Add Comment
Please, Sign In to add comment