
"Le sans fil est facilité!" - Ajout de la connexion LORA Peer-to-Peer à une application Lorawan existante

Sous réserve de votre conformité avec ces termes, vous pouvez utiliser des logiciels Microchip et toutes les dérivés exclusivement avec des produits Microchip. Il est de votre responsabilité de vous conformer aux termes de licence tiers applicables à votre utilisation de logiciels tiers (y compris des logiciels open source) qui peuvent accompagner le logiciel Microchip.
Ce logiciel est fourni par Microchip "tel quel". Aucune garantie, qu'exprimée, implicite ou statutaire, ne s'applique à ce logiciel, y compris toutes les garanties implicites de non-contrefaçon, de qualité marchande et d'adéquation à un usage particulier.
En aucun cas, Microchip ne sera responsable de toute perte, dommage, coût ou dépense spécial, punitif, punitif, accessoire ou consécutif, les dommages, les coûts ou les dépenses de toute nature liés au logiciel, aussi causés, même si la micropuce a été informée de la possibilité ou des dommages sont prévisibles. Dans toute la mesure autorisée par la loi, la responsabilité totale de Microchip sur toutes les réclamations de quelque manière liée à ce logiciel ne dépassera pas le montant des frais, le cas échéant, que vous avez payé directement à Microchip pour ce logiciel.
Interagissez avec vos pairs sur ce logiciel dans Lora Forum.
Sur la base de l'application Lorawan Mote générée à partir d'ASFV3, cet exemple de code démontre la coexistence d'une application Lorawan et une communication radio pure entre 2x ATSAMR34 XPlatenhed Pro Boards en utilisant la modulation LORA.
Pour plus d'informations sur les appareils Microchip ATSAMR34 LORA SIP, visitez la page Web Microchip:
https://www.microchip.com/design-centers/wireless-connectivity/low-power-wide-area-networks/lora-technology/sam-r34-r35

Le kit d'évaluation PRSAMR34 XPlated Pro est une plate-forme matérielle utilisée pour évaluer la SIP LORA® LORA® sous-GHZ ATSAMR34. Il est pris en charge par Microchip Studio 7.0 IDE et une collection d'échantillons de codes est disponible auprès de Advanced Software Framework (ASFV3) depuis la version 3.44.0. Le kit d'évaluation de la série PRO MCU XPlated comprend un débogueur intégré à bord (EDBG), et aucun outil externe n'est nécessaire pour programmer ou déboguer l'ATSAMR34. Le kit propose un ensemble de fonctionnalités qui permettent à l'utilisateur de commencer les périphériques SIP SIP ATSAMR34 Low Power Lora® Sub-GHz et de comprendre comment intégrer l'appareil dans votre propre conception. Le kit ATSAMR34 Xplagé Pro contient les éléments suivants:

Pour démontrer la communication entre pairs, vous avez besoin d'au moins 2x planches pro-ATSAMR34 XPlated Pro.
Ce projet intègre l'API logiciel Microchip Lorawan Stack (MLS) qui fournit une interface aux différents modules logiciels.
Pour cette application, nous «une pause» de la couche Lorawan Mac (MAC) et utiliserons la couche radio Lorawan (TAL) pour la communication entre pairs et «reprendre» la couche Lorawan Mac pour effectuer les opérations de Lorawan.
Dans la configuration entre pairs, la couche Lorawan Mac est contournée et laisse la possibilité de conduire directement la radio sans protocole, sans sécurité, sans identifiant unique pour un appareil et évidemment aucune interopérabilité et écosystème (en opposé avec Lorawan). Cela peut servir à démontrer la possibilité d'utiliser la communication P2P dans une application Lorawan.
Veuillez vous assurer de ne pas violer les réglementations locales pour les bandes de fréquence correspondantes. Par exemple, 25MW et 1% de cycle de service pour la bande 868 MHz en Europe.

La couche MAC fournit la fonctionnalité des opérations définies dans la spécification Lorawan.
La couche TAL utilise les pilotes de radio et donne accès au rédacteur SX1276.
Pour pouvoir configurer les appareils pour une connexion point à point, le code doit:
void LORAWAN_Init(AppDataCb_t appdata, JoinResponseCb_t joindata);
StackRetStatus_t LORAWAN_Reset (IsmBand_t ismBand);
uint32_t LORAWAN_Pause (void);
RadioError_t RADIO_SetAttr(RadioAttribute_t attribute, void *value);
RADIO_SetAttr(WATCHDOG_TIMEOUT,(void *)&wdt) ;
RadioError_t RADIO_Receive(RadioReceiveParam_t *param);
Cette fonction définit l'appareil en mode de réception pour recevoir des données et les stocker dans l'espace du pointeur de tampon en faisant un article de tâche sur Radio_RXHandler.
RadioError_t RADIO_Transmit(RadioTransmitParam_t *param);
Cette fonction transmet les données en faisant un article de tâche sur Radio_TXHandler.
Pour la communication entre pairs, l'exemple de code configure la radio avec les paramètres suivants:
typedef enum _AppTaskIds_t
{
DISPLAY_TASK_HANDLER,
PROCESS_TASK_HANDLER,
APP_TASKS_COUNT
}AppTaskIds_t;
typedef enum _AppTaskState_t
{
RESTORE_BAND_STATE,
DEMO_CERT_APP_STATE,
DEMO_APP_STATE,
JOIN_SEND_STATE
}AppTaskState_t;
static SYSTEM_TaskStatus_t (*appTaskHandlers[APP_TASKS_COUNT])(void) = {
/* In the order of descending priority */
displayTask,
processTask
};
appTaskState = JOIN_SEND_STATE;
appPostTask(DISPLAY_TASK_HANDLER);
/*********************************************************************//**
brief Calls appropriate functions based on state variables
*************************************************************************/
static SYSTEM_TaskStatus_t displayTask(void)
{
switch(appTaskState)
{
case RESTORE_BAND_STATE:
displayRunRestoreBand();
break;
case DEMO_CERT_APP_STATE:
displayRunDemoCertApp();
break;
case DEMO_APP_STATE:
displayRunDemoApp();
break;
case JOIN_SEND_STATE:
displayJoinAndSend();
break;
default:
printf("Error STATE Enteredrn");
break;
}
return SYSTEM_TASK_SUCCESS;
}
/*********************************************************************//**
brief Displays and activates LED's for joining to a network
and sending data to a network
*************************************************************************/
static void displayJoinAndSend(void)
{
printf("rn1. Send Join Requestrn");
printf("2. Send Datarn");
// new menu with p2p
printf("3. Main Menurn") ;
printf("4. MAC Pausern") ;
printf("5. MAC Resumern") ;
printf("6. Configure Radiorn") ;
printf("7. Send Radio Datarn") ;
printf("8. Enter Radio Receive modern") ;
printf("9. Exit Radio Receive modern") ;
#ifdef CONF_PMM_ENABLE
printf("0. Sleeprn") ;
#endif
printf("rnEnter your choice: ");
set_LED_data(LED_AMBER,&off);
set_LED_data(LED_GREEN,&off);
startReceiving = true;
}
/*********************************************************************//**
brief Pulls the data from UART when activated
*************************************************************************/
void serial_data_handler(void)
{
int rxChar;
char serialData;
/* verify if there was any character received*/
if (startReceiving == true)
{
if((-1) != (rxChar = sio2host_getchar_nowait()))
{
serialData = (char)rxChar;
if((serialData != 'r') && (serialData != 'n') && (serialData != 'b'))
{
startReceiving = false;
serialBuffer = rxChar;
appPostTask(PROCESS_TASK_HANDLER);
printf("rn");
}
}
}
}
/*********************************************************************//**
brief Calls appropriate functions based on state variables
*************************************************************************/
static SYSTEM_TaskStatus_t processTask(void)
{
switch(appTaskState)
{
case RESTORE_BAND_STATE:
processRunRestoreBand();
break;
case DEMO_CERT_APP_STATE:
processRunDemoCertApp();
break;
case DEMO_APP_STATE:
processRunDemoApp();
break;
case JOIN_SEND_STATE:
processJoinAndSend();
break;
default:
printf("Error STATE Enteredrn");
break;
}
return SYSTEM_TASK_SUCCESS;
}
/*********************************************************************//**
brief Sends Join request or Data to the network
*************************************************************************/
static void processJoinAndSend(void)
{
StackRetStatus_t status = LORAWAN_SUCCESS;
if(serialBuffer == '1')
{
status = LORAWAN_Join(DEMO_APP_ACTIVATION_TYPE);
if (LORAWAN_SUCCESS == (StackRetStatus_t)status)
{
set_LED_data(LED_GREEN,&on);
printf("nJoin Request Sentnr");
}
else
{
set_LED_data(LED_AMBER,&on);
print_stack_status(status);
appTaskState = JOIN_SEND_STATE;
appPostTask(DISPLAY_TASK_HANDLER);
}
}
else if(serialBuffer == '2' && joined == true)
{
sendData();
}
else if(serialBuffer == '2' && !joined)
{
set_LED_data(LED_AMBER,&on);
printf("Device not joined to the networkrn");
appTaskState = JOIN_SEND_STATE;
appPostTask(DISPLAY_TASK_HANDLER);
}
#ifdef CONF_PMM_ENABLE
else if(serialBuffer == '0')
{
static bool deviceResetsForWakeup = false;
PMM_SleepReq_t sleepReq;
/* Put the application to sleep */
sleepReq.sleepTimeMs = DEMO_CONF_DEFAULT_APP_SLEEP_TIME_MS;
sleepReq.pmmWakeupCallback = appWakeup;
sleepReq.sleep_mode = CONF_PMM_SLEEPMODE_WHEN_IDLE;
if (CONF_PMM_SLEEPMODE_WHEN_IDLE == SLEEP_MODE_STANDBY)
{
deviceResetsForWakeup = false;
}
if (true == LORAWAN_ReadyToSleep(deviceResetsForWakeup))
{
app_resources_uninit();
if (PMM_SLEEP_REQ_DENIED == PMM_Sleep(&sleepReq))
{
HAL_Radio_resources_init();
sio2host_init();
appTaskState = JOIN_SEND_STATE;
appPostTask(DISPLAY_TASK_HANDLER);
printf("rnsleep_not_okrn");
}
}
else
{
printf("rnsleep_not_okrn");
appTaskState = JOIN_SEND_STATE;
appPostTask(DISPLAY_TASK_HANDLER);
}
}
#endif
else if (serialBuffer == '3')
{
// main menu
appTaskState = DEMO_APP_STATE;
appPostTask(DISPLAY_TASK_HANDLER);
}
else if (serialBuffer == '4')
{
// Pause the Microchip LoRaWAN Stack
uint32_t time_ms ;
time_ms = LORAWAN_Pause() ;
printf("rnMAC Pause %ldrn", time_ms) ;
appTaskState = JOIN_SEND_STATE ;
appPostTask(DISPLAY_TASK_HANDLER) ;
}
else if (serialBuffer == '5')
{
// Resume the Microchip LoRaWAN Stack
LORAWAN_Resume() ;
printf("rnMAC Resumern") ;
appTaskState = JOIN_SEND_STATE ;
appPostTask(DISPLAY_TASK_HANDLER) ;
}
else if (serialBuffer == '6')
{
// Configure Radio Parameters
// --------------------------
// Bandwidth = BW_125KHZ
// Channel frequency = FREQ_868100KHZ
// Channel frequency deviation = 25000
// CRC = enabled
// Error Coding Rate = 4/5
// IQ Inverted = disabled
// LoRa Sync Word = 0x34
// Modulation = LoRa
// PA Boost = disabled (disabled for EU , enabled for NA)
// Output Power = 1 (up to +14dBm for EU / up to +20dBm for NA)
// Spreading Factor = SF7
// Watchdog timeout = 60000
// Bandwidth
RadioLoRaBandWidth_t bw = BW_125KHZ ;
RADIO_SetAttr(BANDWIDTH, &bw) ;
printf("Configuring Radio Bandwidth: 125kHzrn") ;
// Channel Frequency
uint32_t freq = FREQ_868100KHZ ;
RADIO_SetAttr(CHANNEL_FREQUENCY, &freq) ;
printf("Configuring Channel Frequency %ldrn", freq) ;
// Channel Frequency Deviation
uint32_t fdev = 25000 ;
RADIO_SetAttr(CHANNEL_FREQUENCY_DEVIATION, &fdev) ;
printf("Configuring Channel Frequency Deviation %ldrn", fdev) ;
// CRC
uint8_t crc_state = 1 ;
RADIO_SetAttr(CRC, &crc_state) ;
printf("Configuring CRC state: %drn", crc_state) ;
// Error Coding Rate
RadioErrorCodingRate_t cr = CR_4_5 ;
RADIO_SetAttr(ERROR_CODING_RATE, &cr) ;
printf("Configuring Error Coding Rate 4/5rn") ;
// IQ Inverted
uint8_t iqi = 0 ;
RADIO_SetAttr(IQINVERTED, &iqi) ;
printf("Configuring IQ Inverted: %drn", iqi) ;
// LoRa Sync Word
uint8_t sync_word = 0x34 ;
RADIO_SetAttr(LORA_SYNC_WORD, &sync_word) ;
printf("Configuring LoRa sync word 0x%xrn", sync_word) ;
// Modulation
RadioModulation_t mod = MODULATION_LORA ;
RADIO_SetAttr(MODULATION, &mod) ;
printf("Configuring Modulation: LORArn") ;
// PA Boost
uint8_t pa_boost = 0 ;
RADIO_SetAttr(PABOOST, &pa_boost) ;
printf("Configuring PA Boost: %drn", pa_boost) ;
// Tx Output Power
int16_t outputPwr = 1 ;
RADIO_SetAttr(OUTPUT_POWER, (void *)&outputPwr) ;
printf("Configuring Radio Output Power %drn", outputPwr) ;
// Spreading Factor
int16_t sf = SF_7 ;
RADIO_SetAttr(SPREADING_FACTOR, (void *)&sf) ;
printf("Configuring Radio SF %drn", sf) ;
// Watchdog Timeout
uint32_t wdt = 60000 ;
RADIO_SetAttr(WATCHDOG_TIMEOUT, (void *)&wdt) ;
printf("Configuring Radio Watch Dog Timeout %ldrn", wdt) ;
appTaskState = JOIN_SEND_STATE ;
appPostTask(DISPLAY_TASK_HANDLER) ;
}
else if (serialBuffer == '7')
{
// Radio Transmit
// the counter value
counter++ ;
if (counter > 255) counter = 0 ;
tx_buffer[0] = counter ;
printf("Buffer transmitted: ") ;
print_array(tx_buffer, 1) ;
RadioError_t radioStatus ;
RadioTransmitParam_t radioTransmitParam ;
radioTransmitParam.bufferLen = 1 ;
radioTransmitParam.bufferPtr = (uint8_t *)&tx_buffer ;
radioStatus = RADIO_Transmit(&radioTransmitParam) ;
switch (radioStatus)
{
case ERR_NONE:
{
printf("Radio Transmit Successrn") ;
}
break ;
case ERR_DATA_SIZE:
{
// do nothing, status already set to invalid
}
break ;
default:
{
printf("Radio Busyrn") ;
}
}
appTaskState = JOIN_SEND_STATE ;
appPostTask(DISPLAY_TASK_HANDLER) ;
}
else if (serialBuffer == '8')
{
// Enter Radio Receive mode
RadioReceiveParam_t radioReceiveParam ;
uint32_t rxTimeout = 0 ; // forever
radioReceiveParam.action = RECEIVE_START ;
radioReceiveParam.rxWindowSize = rxTimeout ;
if (RADIO_Receive(&radioReceiveParam) == 0)
{
printf("Radio in Receive modern") ;
}
appTaskState = JOIN_SEND_STATE ;
appPostTask(DISPLAY_TASK_HANDLER) ;
}
else if (serialBuffer == '9')
{
// Stop Radio Receive mode
RadioReceiveParam_t radioReceiveParam ;
radioReceiveParam.action = RECEIVE_STOP ;
if (RADIO_Receive(&radioReceiveParam) == 0)
{
printf("Radio Exit Receive modern") ;
}
appTaskState = JOIN_SEND_STATE ;
appPostTask(DISPLAY_TASK_HANDLER) ;
}
else
{
set_LED_data(LED_AMBER,&on);
printf("Invalid choice enteredrn");
appTaskState = JOIN_SEND_STATE;
appPostTask(DISPLAY_TASK_HANDLER);
}
}
/* OTAA Join Parameters */
#define DEMO_DEVICE_EUI {0xde, 0xaf, 0xfa, 0xce, 0xde, 0xaf, 0xfa, 0xce}
#define DEMO_APPLICATION_EUI {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05}
#define DEMO_APPLICATION_KEY {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05}
Fichier conf_board.h:
/* TODO: If Board is having EDBG with DEV_EUI flashed in
Userpage Enable this Macro otherwise make it as 0 */
#define EDBG_EUI_READ 1







