Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

Commit

Permalink
Updated project.gmk with us915. Updated main.c with updated code for …
Browse files Browse the repository at this point in the history
…aquiring RFID tag from log.out file
  • Loading branch information
Ryan committed Feb 27, 2019
1 parent f5e8c00 commit b6f66c2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/projects.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# working in EU868 MHz Band

# LMIC CONFIG
LMICCFG += -DCFG_DEBUG -DCFG_eu868 -DCFG_sx1276_radio -DDEBUG_LMIC -DDEBUG_HAL
LMICCFG += -DCFG_DEBUG -DCFG_us915 -DCFG_sx1276_radio -DDEBUG_LMIC -DDEBUG_HAL

CCOPTS = -c -std=gnu99

Expand Down
102 changes: 80 additions & 22 deletions examples/transmit/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,31 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#define _OPEN_SYS_ITOA_EXT

#include "lmic.h"
#include "debug.h"

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

//////////////////////////////////////////////////
// CONFIGURATION (FOR APPLICATION CALLBACKS BELOW)
//////////////////////////////////////////////////

// application router ID (LSBF)
static const u1_t APPEUI[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xFF, 0xC0 };
static const u1_t APPEUI[8] = { 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x };

// unique device ID (LSBF)
static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
static const u1_t DEVEUI[8] = { 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x };

// device-specific AES key (derived from device EUI)
static const u1_t DEVKEY[16] = { 0xAB, 0x89, 0xEF, 0xCD, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA };
static const u1_t DEVKEY[16] = { 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x, 0x };


//////////////////////////////////////////////////
Expand Down Expand Up @@ -79,7 +89,7 @@ static void initfunc (osjob_t* j) {
// application entry point
int main () {
osjob_t initjob;

// initialize runtime env
os_init();
// initialize debug library
Expand All @@ -99,25 +109,73 @@ int main () {

void onEvent (ev_t ev) {
debug_event(ev);

switch(ev) {

// network joined, session established
case EV_JOINED:
debug_val("netid = ", LMIC.netid);
goto tx;

// scheduled data sent (optionally data received)
case EV_TXCOMPLETE:
if(LMIC.dataLen) { // data received in rx slot after tx
debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
}
tx:
// immediately prepare next transmission
LMIC.frame[0] = LMIC.snr;
// schedule transmission (port 1, datalen 1, no ack requested)
LMIC_setTxData2(1, LMIC.frame, 1, 0);
// (will be sent as soon as duty cycle permits)
break;
// network joined, session established
case EV_JOINED:
debug_val("netid = ", LMIC.netid);
goto tx;

// scheduled data sent (optionally data received)
case EV_TXCOMPLETE:
if(LMIC.dataLen) { // data received in rx slot after tx
debug_buf(LMIC.frame+LMIC.dataBeg, LMIC.dataLen);
}
static const char* fn = "/home/pi/setup/log.out";
int fd;
tx:
// immediately prepare next transmission
fd = open(fn, O_RDWR);
if(fd < 0) {
perror(fn);
exit(EXIT_FAILURE);
}

char data[10];
char buffer[10];
int rc = read(fd, &data, 10);
if (rc < 0) {
perror("bad stuff.");
exit(EXIT_FAILURE);
}
/* // Found at: https://codereview.stackexchange.com/questions/156477/c-program-to-count-number-of-lines-in-a-file
while ((bytes = fread(buffer, 1, sizeof(buffer) - 1, fd))) {
lastchar = buffer[bytes - 1];
for (char *c = buffer; (c = memchr(c, '\n', bytes - (c - buffer))); c++) {
lines++;
}
}
*/
close(fd);
debug_str("#############################################################");
debug_str(data);
debug_str("#############################################################");

for(int i =0; i < strlen(data); i++) {
//LMIC.frame[i] = sprintf(buffer, "%x", data[i]);

LMIC.frame[i] = data[i];
}

/*
LMIC.frame[0] = 0x0;
LMIC.frame[1] = 0x1;
LMIC.frame[2] = 0x1;
LMIC.frame[3] = 0x0;
LMIC.frame[4] = 0x1;
LMIC.frame[5] = 0x6;
LMIC.frame[6] = 0xa;
LMIC.frame[7] = 0x3;
LMIC.frame[8] = 0x2;
LMIC.frame[9] = 0xf;
*/

//LMIC.frame[0] = LMIC.snr;
// schedule transmission (port 1, datalen 1, no ack requested)
LMIC_setTxData2(1, LMIC.frame, 10, 1);
// (will be sent as soon as duty cycle permits)
break;
}
}

0 comments on commit b6f66c2

Please sign in to comment.