Fix PB Encoding

This commit is contained in:
Ryan Alder 2020-02-22 16:39:33 -08:00
parent 60bf5d84d6
commit 5e48c293bf
1 changed files with 15 additions and 12 deletions

View File

@ -1,6 +1,6 @@
#include <SPI.h>
#include <LoRa.h>
#include <TinyGPS.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "pb_common.h"
@ -16,7 +16,7 @@ float lng = 0;
TinyGPSPlus gps;
SoftwareSerial ss(5, 6);
SoftwareSerial ss(6, 7);
void setup() {
Serial.begin(9600);
@ -47,9 +47,9 @@ void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Gather GPS data
if (gps.location.isValid()) {
if (gps.encode(ss.read()) && gps.location.isValid()) {
Serial.println("Valid GPS");
lat = gps.location.lat();
lng = gps.location.lng();
@ -59,17 +59,20 @@ void loop() {
}
// Encode as protobuf packet
if (1) {
uint8_t buffer[10];
Fenceless_Coordinate m = Fenceless_Coordinate_init_zero;
if (lat && lng) {
uint8_t buffer[50] = {0};
Fenceless_CollarResponse m = Fenceless_CollarResponse_init_zero;
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
//m.x = lat;
//m.y = lng;
m.x = 44.558750;
m.y = -123.283744;
m.loc.x = lat;
m.loc.y = lng;
if (!pb_encode(&stream, Fenceless_Coordinate_fields, &m)) {
int status = pb_encode(&stream, Fenceless_CollarResponse_fields, &m);
if (!status) {
Serial.println("Failed to encode");
} else {
Serial.print("Status: ");
Serial.println(status);
}
Serial.print("Sending packet Lat / Long: ");