Select Git revision
CSCE838-Lab4-Node.ino
-
smurray798 authoredsmurray798 authored
CSCE838-Lab4-Node.ino 13.10 KiB
/*******************************************************************************
Copyright (c) 2015 Matthijs Kooijman
Copyright (c) 2018 Terry Moore, MCCI Corporation
Permission is hereby granted, free of charge, to anyone
obtaining a copy of this document and accompanying files,
to do whatever they want with them without any restriction,
including, but not limited to, copying, modification and redistribution.
NO WARRANTY OF ANY KIND IS PROVIDED.
This example transmits data on hardcoded channel and receives data
when not transmitting. Running this sketch on two nodes should allow
them to communicate.
*******************************************************************************/
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <TemperatureZero.h>
/** Defines **/
#define NODE_ID 1
#define NETWORK_FREQUENCY 915
// clock parameters
#define CPU_HZ 48000000
#define TIMER_PRESCALER_DIV 1024
// Error codes
#define ERROR_CODE_MISSING_PACKET 0x01
#define ERROR_CODE_RECEPTION_FAILURE 0x02
#define ERROR_CODE_WDT_EARLY_WARNING 0x04
#define ERROR_CODE_INVALID_TEMPERATURE 0x08
#define ERROR_CODE_MISMATCHED_PACKET_NUM 0x10
/** Type Definitions **/
typedef struct
{
uint8_t NodeID;
uint16_t PacketID;
uint32_t Timestamp;
float AverageTemperature;
uint8_t ErrorType;
} Lab3Packet_t;
/** Static Variables **/
static TemperatureZero TempZero = TemperatureZero();
static float g_temperature_samples[5];
static float g_temperature_samples_count = 0;
static int32_t initialMillis = 0;
static volatile Lab3Packet_t txPacket;
static volatile unsigned int counterISR = 1;
// we formerly would check this configuration; but now there is a flag,
// in the LMIC, LMIC.noRXIQinversion;
// if we set that during init, we get the same effect. If
// DISABLE_INVERT_IQ_ON_RX is defined, it means that LMIC.noRXIQinversion is
// treated as always set.
//
// #if !defined(DISABLE_INVERT_IQ_ON_RX)
// #error This example requires DISABLE_INVERT_IQ_ON_RX to be set. Update \
// lmic_project_config.h in arduino-lmic/project_config to set it.
// #endif
// How often to send a packet. Note that this sketch bypasses the normal
// LMIC duty cycle limiting, so when you change anything in this sketch
// (payload length, frequency, spreading factor), be sure to check if
// this interval should not also be increased.
// See this spreadsheet for an easy airtime and duty cycle calculator:
// https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc
#define TX_INTERVAL 60000 //Delay between each message in millisecond.