move lora transmission to timer
This commit is contained in:
parent
5a7003d621
commit
f51f10574c
52
collar.cpp
52
collar.cpp
|
@ -37,7 +37,8 @@ uint8_t DevAddr[4] = {0x26, 0x02, 0x12, 0xB6};
|
|||
unsigned char loraData[50] = {"hello LoRa"};
|
||||
|
||||
// How many times data transfer should occur, in seconds
|
||||
const unsigned int sendInterval = 30;
|
||||
// const unsigned int sendInterval = 30;
|
||||
const unsigned int sendInterval = 60;
|
||||
|
||||
// Pinout for Adafruit Feather 32u4 LoRa
|
||||
TinyLoRa lora = TinyLoRa(2, 10, 9);
|
||||
|
@ -61,7 +62,7 @@ void clear_verts() {
|
|||
n_poly=0;
|
||||
}
|
||||
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
|
||||
{ //from stack overflow
|
||||
{ //from stack overflow, check that coordinate is within polygon boundary
|
||||
int i, j, c = 0;
|
||||
for (i = 0, j = nvert-1; i < nvert; j = i++) {
|
||||
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
|
||||
|
@ -160,33 +161,37 @@ void setup()
|
|||
while(true);
|
||||
}
|
||||
|
||||
Fenceless_Coordinates coords;
|
||||
coords.isr = 10;
|
||||
coords.coord0.x = 1; coords.coord0.y = 2;
|
||||
coords.coord1.x = 1; coords.coord1.y = 2;
|
||||
coords.coord2.x = 1; coords.coord2.y = 2;
|
||||
coords.coord3.x = 1; coords.coord3.y = 2;
|
||||
coords.coord4.x = 1; coords.coord4.y = 2;
|
||||
coords.coord5.x = 1; coords.coord5.y = 2;
|
||||
coords.coord6.x = 1; coords.coord6.y = 2;
|
||||
coords.coord7.x = 1; coords.coord7.y = 2;
|
||||
coords.coord8.x = 1; coords.coord8.y = 2;
|
||||
coords.coord9.x = 1; coords.coord9.y = 2;
|
||||
Fenceless_CollarResponse coord;
|
||||
coord.loc.x = 0;
|
||||
coord.loc.y = 0;
|
||||
|
||||
pb_ostream_t stream;
|
||||
stream = pb_ostream_from_buffer(loraData, sizeof(loraData));
|
||||
int err = pb_encode(&stream, Fenceless_Coordinates_fields, &coords);
|
||||
int err = pb_encode(&stream, Fenceless_CollarResponse_fields, &coord);
|
||||
// Optional set transmit power. If not set default is +17 dBm.
|
||||
// Valid options are: -80, 1 to 17, 20 (dBm).
|
||||
// For safe operation in 20dBm: your antenna must be 3:1 VWSR or better
|
||||
// and respect the 1% duty cycle.
|
||||
|
||||
lora.setPower(1);
|
||||
|
||||
// start 1 second timer
|
||||
TCCR1A = 0;
|
||||
TCCR1B = 0;
|
||||
|
||||
TCNT1 = 34286; // preload timer
|
||||
TCCR1B |= (1 << CS12); // 256 prescaler
|
||||
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
|
||||
|
||||
Serial.println("OK");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int sendCounter = 0;
|
||||
ISR(TIMER1_OVF_vect) {
|
||||
digitalWrite(LED_BUILTIN, sendCounter%2);
|
||||
if(sendCounter==0) {
|
||||
sendCounter = sendInterval;
|
||||
|
||||
Serial.println("Sending LoRa Data...");
|
||||
lora.sendData(loraData, sizeof(loraData), lora.frameCounter);
|
||||
// Optionally set the Frame Port (1 to 255)
|
||||
|
@ -195,17 +200,16 @@ void loop()
|
|||
Serial.print("Frame Counter: ");Serial.println(lora.frameCounter);
|
||||
lora.frameCounter++;
|
||||
|
||||
// blink LED to indicate packet sent
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
Serial.println("delaying...");
|
||||
|
||||
}
|
||||
sendCounter--;
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
if(recieved) {
|
||||
Serial.println("Recieved something");
|
||||
} else {
|
||||
Serial.println("Nothing yet");
|
||||
}
|
||||
delay(sendInterval * 1000);
|
||||
delay(1000);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user