Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions examples/RPC/LORA_EdgeControl/LORA_EdgeControl.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// LoRa example for the Edge control.
//
// This script configures your Arduino Edge control to receive Lora messages from another Arduino.
// Requirements:
// 1 Edge Control board
// 2 MKR1300/1310 boards (sender and receiver)
//
// Connect one of the MKR1300 to the MKR2 socket in the EdgeControl board
// This script is designed to pair with "LORA_receiver-EC.ino". Also
// you will need a LoRa transmitter. We have used the LoRa Sender example from the other
// MKR1300.
//
// The sketch make use of the OpenMV RPC library for communicating between the EdgeControl
// and the MKR1300 via UART
//
// Created 20 April. 2021
// by e.lopez


#include <Arduino_EdgeControl.h>
#include <openmvrpc.h>

openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer.
openmv::rpc_hardware_serial1_uart_master rpc(115200);

//LoRa message received interrupt pin
const byte interruptPin = PIN_WIRE_SCL1;

bool message_received = false;
uint16_t msg_count {0};


//////////////////////////////////////////////////////////////
// Call Back Handlers
//////////////////////////////////////////////////////////////

void rpc_retrieve_LoRa_data()
{
rpc.begin();
void *message;
size_t result_data_len;

if (rpc.call_no_copy_no_args(F("retrieve_msg"), &message, &result_data_len) ) {

char buff[result_data_len + 1]; memset(buff, 0, result_data_len + 1);
// Copy what we received into our data type container.
memcpy(buff, message, result_data_len);
// Use it now.
Serial.print(F(": "));
Serial.println(buff);

//print on LCD
//LCD.setCursor(0, 0);
//LCD.print("LoRa MSG:");
//LCD.setCursor(0, 1);
//LCD.print(buff);

} else {
Serial.print(F("Error:rpc_retrieve_LoRa_data() failed! "));
}
rpc.end();
}

//*******************
//SETUP
//*******************
void setup()
{
//LoRa data available interrupt
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), LoRa_ISR, FALLING);

EdgeControl.begin();

Power.on(PWR_3V3);
Power.on(PWR_VBAT);

Power.on(PWR_MKR2);
delay(5000); // Wait for MKR2 to power-on'

Serial.begin(115200);
while (!Serial);

// //LCD init
// LCD.begin(16, 2); // set up the LCD's number of columns and rows:
// LCD.home(); // go home
// LCD.backlight(); // turn on Backlight
// LCD.print("EDGE:"); // Print a message to the LCD.

String serialNumber = EdgeControl.serialNumber();
Serial.print("Serial Number: ");
Serial.println(serialNumber);
}

//*******************
//LOOP
//*******************
void loop()
{
if (message_received) {
Serial.print("Message ");
Serial.print(++msg_count);
rpc_retrieve_LoRa_data();
message_received = false;
}
}

void LoRa_ISR() {
message_received = true;
}
90 changes: 90 additions & 0 deletions extras/RPC/LORA_Receiver-EC/LORA_Receiver-EC.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// LoRa example for the Edge control.
//
// This script configures your MKR1300 to receive Lora messages and send it to the
// Arduino Edge control.
//
// Connect one of the MKR1300 to the MKR2 socket in the EdgeControl board
// This script is designed to pair with "LORA_EdgeControl.ino". Also
// you will need a LoRa transmitter. We have used the LoRa Sender example from the other
// MKR1300.
//
// The sketch make use of the OpenMV RPC library for communicating between the EdgeControl
// and the MKR1300 via UART
//
// Created 20 April. 2021
// by e.lopez

#include <SPI.h>
#include <LoRa.h>
#include <openmvrpc.h>

openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer.
openmv::rpc_callback_buffer<8> callback_buffer; // All RPC objects share this buffer.
openmv::rpc_hardware_serial_uart_slave rpc(115200);

String LoRa_data = "";
//output interrupt pin
constexpr uint8_t interruptPin {12};

//***********************
// Call Backs
//***********************
//**** retrieve data ****
void rpc_retrieve_LoRa_msg(void **in_data, size_t* in_data_len) {

size_t LoRa_data_len = sizeof(LoRa_data);
memcpy(in_data, &LoRa_data, LoRa_data_len);
}

//***********************
// LoRa
//***********************
void ParsePacket_LoRa() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
LoRa_data = "";
while (LoRa.available()) {
LoRa_data += (char)LoRa.read();
}
Serial.print(LoRa_data);
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
//trigger the interrupt
digitalWrite(interruptPin, LOW);
delay(1);
digitalWrite(interruptPin, HIGH);
}
}

//***********************
// SETUP
//***********************
void setup() {
pinMode(interruptPin, OUTPUT);
digitalWrite(interruptPin, HIGH);
//register callback
rpc.register_callback(F("retrieve_msg"), rpc_retrieve_LoRa_msg);
//rpc init
rpc.begin();
//Serial init
Serial.begin(115200);
while (!Serial);
//LoRa init
Serial.println("LoRa Receiver");
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}

//***********************
// LOOP
//***********************
void loop() {
ParsePacket_LoRa();
rpc.loop();
}