Saltar al contenido

ejemplo de código arduino del nodo lora

Ejemplo: lora node arduino

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>// LoRaWAN NwkSKey, network session keystaticconstPROGMEM u1_t NWKSKEY[16]=0xAE,0xBD,0x9B,0xBC,0x43,0x41,0xFB,0x47,0x3D,0xA5,0x8D,0x0D,0x48,0x98,0xEF,0xCF;// LoRaWAN AppSKey, application session keystaticconst u1_t PROGMEMAPPSKEY[16]=0xE1,0x51,0x0F,0xB1,0x59,0x4C,0xC8,0xD7,0xAA,0x43,0xAC,0xE7,0xE2,0xBC,0x5F,0x1B;// LoRaWAN end-device address (DevAddr)staticconst u4_t DEVADDR=0x260314F7;// These callbacks are only used in over-the-air activation, so they are// left empty here (we cannot leave them out completely unless// DISABLE_JOIN is set in config.h, otherwise the linker will complain).voidos_getArtEui(u1_t* buf)voidos_getDevEui(u1_t* buf)voidos_getDevKey(u1_t* buf)static uint8_t mydata[]="HI,Lora World!";static osjob_t sendjob;// Schedule data trasmission in every this many seconds (might become longer due to duty// cycle limitations).// we set 10 seconds intervalconst unsigned TX_INTERVAL=10;// Pin mapping according to Cytron LoRa Shield RFMconst lmic_pinmap lmic_pins =.nss=10,.rxtx=LMIC_UNUSED_PIN,.rst=7,.dio=2,5,6,;voidonEvent(ev_t ev)Serial.print(os_getTime());Serial.print(": ");switch(ev)caseEV_TXCOMPLETE:Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));// Schedule next transmissionos_setTimedCallback(&sendjob,os_getTime()+sec2osticks(TX_INTERVAL), do_send);break;default:Serial.println(F("Unknown event"));break;voiddo_send(osjob_t* j)// Check if there is not a current TX/RX job runningif(LMIC.opmode&OP_TXRXPEND)Serial.println(F("OP_TXRXPEND, not sending"));else// Prepare upstream data transmission at the next possible time.LMIC_setTxData2(1, mydata,sizeof(mydata)-1,0);Serial.println(F("Packet queued"));// Next TX is scheduled after TX_COMPLETE event.voidsetup()Serial.begin(115200);Serial.println(F("Starting"));// LMIC initos_init();// Reset the MAC state. Session and pending data transfers will be discarded.LMIC_reset();// Set static session parameters. Instead of dynamically establishing a session// by joining the network, precomputed session parameters are be provided.
	uint8_t appskey[sizeof(APPSKEY)];
	uint8_t nwkskey[sizeof(NWKSKEY)];memcpy_P(appskey,APPSKEY,sizeof(APPSKEY));memcpy_P(nwkskey,NWKSKEY,sizeof(NWKSKEY));LMIC_setSession(0x1,DEVADDR, nwkskey, appskey);// Select frequencies rangeLMIC_selectSubBand(3);// Disable link check validationLMIC_setLinkCheckMode(0);// Disable ADRLMIC_setAdrMode(false);// TTN uses SF9 for its RX2 window.LMIC.dn2Dr=DR_SF9;// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)LMIC_setDrTxpow(DR_SF7,14);// Start jobdo_send(&sendjob);voidloop()os_runloop_once();

Comentarios y valoraciones del post

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *