kopia lustrzana https://github.com/helium/longfi-arduino
fixes
rodzic
c4c3f1eab0
commit
09b9968f4b
|
@ -35,12 +35,11 @@
|
||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
#include <lmic.h>
|
#include <lmic.h>
|
||||||
|
|
||||||
|
#include <CayenneLPP.h>
|
||||||
#include <MicroNMEA.h>
|
#include <MicroNMEA.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <CayenneLPP.h>
|
|
||||||
|
|
||||||
//I2C communication parameters
|
// I2C communication parameters
|
||||||
#define DEFAULT_DEVICE_ADDRESS 0x3A
|
#define DEFAULT_DEVICE_ADDRESS 0x3A
|
||||||
#define DEFAULT_DEVICE_PORT 0xFF
|
#define DEFAULT_DEVICE_PORT 0xFF
|
||||||
#define I2C_DELAY 1
|
#define I2C_DELAY 1
|
||||||
|
@ -63,8 +62,8 @@ static const u1_t PROGMEM APPKEY[16] = {0};
|
||||||
void os_getDevKey(u1_t *buf) { memcpy_P(buf, APPKEY, 16); }
|
void os_getDevKey(u1_t *buf) { memcpy_P(buf, APPKEY, 16); }
|
||||||
|
|
||||||
CayenneLPP lpp(51);
|
CayenneLPP lpp(51);
|
||||||
TwoWire& gps = DEV_I2C;
|
TwoWire &gps = DEV_I2C;
|
||||||
//I2C read data structures
|
// I2C read data structures
|
||||||
char buff[32];
|
char buff[32];
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
|
@ -137,44 +136,37 @@ const lmic_pinmap lmic_pins = *Arduino_LMIC::GetPinmap_Disco_L072cz_Lrwan1();
|
||||||
#error "Unknown target"
|
#error "Unknown target"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ppsHandler(void)
|
void ppsHandler(void) { ppsTriggered = true; }
|
||||||
{
|
|
||||||
ppsTriggered = true;
|
void gpsHardwareReset() {
|
||||||
|
// reset the device
|
||||||
|
digitalWrite(RESET_PIN, LOW);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
|
// wait for reset to apply
|
||||||
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpsHardwareReset()
|
// Read 32 bytes from I2C
|
||||||
{
|
void readI2C(char *inBuff) {
|
||||||
//reset the device
|
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
||||||
digitalWrite(RESET_PIN, LOW);
|
gps.write((uint8_t)DEFAULT_DEVICE_PORT);
|
||||||
delay(50);
|
gps.endTransmission(false);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
gps.requestFrom((uint8_t)DEFAULT_DEVICE_ADDRESS, (uint8_t)32);
|
||||||
|
int i = 0;
|
||||||
//wait for reset to apply
|
while (gps.available()) {
|
||||||
delay(2000);
|
inBuff[i] = gps.read();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Read 32 bytes from I2C
|
// Send a NMEA command via I2C
|
||||||
void readI2C(char *inBuff)
|
void sendCommand(char *cmd) {
|
||||||
{
|
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
||||||
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
gps.write((uint8_t)DEFAULT_DEVICE_PORT);
|
||||||
gps.write((uint8_t) DEFAULT_DEVICE_PORT);
|
MicroNMEA::sendSentence(gps, cmd);
|
||||||
gps.endTransmission(false);
|
gps.endTransmission(true);
|
||||||
gps.requestFrom((uint8_t)DEFAULT_DEVICE_ADDRESS, (uint8_t) 32);
|
|
||||||
int i = 0;
|
|
||||||
while (gps.available())
|
|
||||||
{
|
|
||||||
inBuff[i]= gps.read();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Send a NMEA command via I2C
|
|
||||||
void sendCommand(char *cmd)
|
|
||||||
{
|
|
||||||
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
|
||||||
gps.write((uint8_t) DEFAULT_DEVICE_PORT);
|
|
||||||
MicroNMEA::sendSentence(gps, cmd);
|
|
||||||
gps.endTransmission(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onEvent(ev_t ev) {
|
void onEvent(ev_t ev) {
|
||||||
|
@ -294,89 +286,86 @@ void onEvent(ev_t ev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void readGPS() {
|
void readGPS() {
|
||||||
//If a message is recieved print all the informations
|
// If a message is recieved print all the informations
|
||||||
if (ppsTriggered)
|
if (ppsTriggered) {
|
||||||
{
|
ppsTriggered = false;
|
||||||
ppsTriggered = false;
|
ledState = !ledState;
|
||||||
ledState = !ledState;
|
digitalWrite(LED_BUILTIN, ledState);
|
||||||
digitalWrite(LED_BUILTIN, ledState);
|
|
||||||
|
|
||||||
// Clear Payload
|
// Clear Payload
|
||||||
lpp.reset();
|
lpp.reset();
|
||||||
|
|
||||||
// Output GPS information from previous second
|
// Output GPS information from previous second
|
||||||
Serial.print("Valid fix: ");
|
Serial.print("Valid fix: ");
|
||||||
Serial.println(nmea.isValid() ? "yes" : "no");
|
Serial.println(nmea.isValid() ? "yes" : "no");
|
||||||
|
|
||||||
Serial.print("Nav. system: ");
|
Serial.print("Nav. system: ");
|
||||||
if (nmea.getNavSystem())
|
if (nmea.getNavSystem())
|
||||||
Serial.println(nmea.getNavSystem());
|
Serial.println(nmea.getNavSystem());
|
||||||
else
|
else
|
||||||
Serial.println("none");
|
Serial.println("none");
|
||||||
|
|
||||||
Serial.print("Num. satellites: ");
|
Serial.print("Num. satellites: ");
|
||||||
Serial.println(nmea.getNumSatellites());
|
Serial.println(nmea.getNumSatellites());
|
||||||
|
|
||||||
Serial.print("HDOP: ");
|
Serial.print("HDOP: ");
|
||||||
Serial.println(nmea.getHDOP()/10., 1);
|
Serial.println(nmea.getHDOP() / 10., 1);
|
||||||
|
|
||||||
Serial.print("Date/time: ");
|
Serial.print("Date/time: ");
|
||||||
Serial.print(nmea.getYear());
|
Serial.print(nmea.getYear());
|
||||||
Serial.print('-');
|
Serial.print('-');
|
||||||
Serial.print(int(nmea.getMonth()));
|
Serial.print(int(nmea.getMonth()));
|
||||||
Serial.print('-');
|
Serial.print('-');
|
||||||
Serial.print(int(nmea.getDay()));
|
Serial.print(int(nmea.getDay()));
|
||||||
Serial.print('T');
|
Serial.print('T');
|
||||||
Serial.print(int(nmea.getHour()));
|
Serial.print(int(nmea.getHour()));
|
||||||
Serial.print(':');
|
Serial.print(':');
|
||||||
Serial.print(int(nmea.getMinute()));
|
Serial.print(int(nmea.getMinute()));
|
||||||
Serial.print(':');
|
Serial.print(':');
|
||||||
Serial.println(int(nmea.getSecond()));
|
Serial.println(int(nmea.getSecond()));
|
||||||
|
|
||||||
long latitude_mdeg = nmea.getLatitude();
|
long latitude_mdeg = nmea.getLatitude();
|
||||||
long longitude_mdeg = nmea.getLongitude();
|
long longitude_mdeg = nmea.getLongitude();
|
||||||
Serial.print("Latitude (deg): ");
|
Serial.print("Latitude (deg): ");
|
||||||
Serial.println(latitude_mdeg / 1000000., 6);
|
Serial.println(latitude_mdeg / 1000000., 6);
|
||||||
|
|
||||||
Serial.print("Longitude (deg): ");
|
Serial.print("Longitude (deg): ");
|
||||||
Serial.println(longitude_mdeg / 1000000., 6);
|
Serial.println(longitude_mdeg / 1000000., 6);
|
||||||
|
|
||||||
long alt;
|
long alt;
|
||||||
Serial.print("Altitude (m): ");
|
Serial.print("Altitude (m): ");
|
||||||
if (nmea.getAltitude(alt))
|
if (nmea.getAltitude(alt))
|
||||||
Serial.println(alt / 1000., 3);
|
Serial.println(alt / 1000., 3);
|
||||||
else
|
else
|
||||||
Serial.println("not available");
|
Serial.println("not available");
|
||||||
|
|
||||||
lpp.addGPS(1, latitude_mdeg, longitude_mdeg, alt);
|
// Pack CayenneLPP Payload
|
||||||
|
lpp.addGPS(1, latitude_mdeg, longitude_mdeg, alt);
|
||||||
|
|
||||||
Serial.print("Speed: ");
|
Serial.print("Speed: ");
|
||||||
Serial.println(nmea.getSpeed() / 1000., 3);
|
Serial.println(nmea.getSpeed() / 1000., 3);
|
||||||
Serial.print("Course: ");
|
Serial.print("Course: ");
|
||||||
Serial.println(nmea.getCourse() / 1000., 3);
|
Serial.println(nmea.getCourse() / 1000., 3);
|
||||||
Serial.println("-----------------------");
|
Serial.println("-----------------------");
|
||||||
nmea.clear();
|
nmea.clear();
|
||||||
|
}
|
||||||
}
|
|
||||||
else
|
while (!ppsTriggered) {
|
||||||
{
|
char c;
|
||||||
char c ;
|
if (idx == 0) {
|
||||||
if (idx == 0)
|
readI2C(buff);
|
||||||
{
|
delay(I2C_DELAY);
|
||||||
readI2C(buff);
|
}
|
||||||
delay(I2C_DELAY);
|
// Fetch the character one by one
|
||||||
}
|
c = buff[idx];
|
||||||
//Fetch the character one by one
|
idx++;
|
||||||
c = buff[idx];
|
idx %= 32;
|
||||||
idx++;
|
// If we have a valid character pass it to the library
|
||||||
idx %= 32;
|
if ((uint8_t)c != 0xFF) {
|
||||||
//If we have a valid character pass it to the library
|
Serial.print(c);
|
||||||
if ((uint8_t) c != 0xFF)
|
nmea.process(c);
|
||||||
{
|
}
|
||||||
Serial.print(c);
|
}
|
||||||
nmea.process(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_send(osjob_t *j) {
|
void do_send(osjob_t *j) {
|
||||||
|
@ -404,7 +393,7 @@ void setup() {
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(LED_BUILTIN, ledState);
|
digitalWrite(LED_BUILTIN, ledState);
|
||||||
|
|
||||||
//Start the module
|
// Start the module
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
Serial.println("Resetting GPS module ...");
|
Serial.println("Resetting GPS module ...");
|
||||||
|
@ -415,30 +404,27 @@ void setup() {
|
||||||
sendCommand((char *)"$PSTMSETPAR,1231,0x00000042");
|
sendCommand((char *)"$PSTMSETPAR,1231,0x00000042");
|
||||||
sendCommand((char *)"$PSTMSAVEPAR");
|
sendCommand((char *)"$PSTMSAVEPAR");
|
||||||
|
|
||||||
//Reset the device so that the changes could take plaace
|
// Reset the device so that the changes could take plaace
|
||||||
sendCommand((char *)"$PSTMSRR");
|
sendCommand((char *)"$PSTMSRR");
|
||||||
|
|
||||||
delay(4000);
|
delay(4000);
|
||||||
|
|
||||||
//Reinitialize I2C after the reset
|
// Reinitialize I2C after the reset
|
||||||
gps.begin();
|
gps.begin();
|
||||||
|
|
||||||
//clear i2c buffer
|
// clear i2c buffer
|
||||||
char c;
|
char c;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
memset(buff, 0, 32);
|
memset(buff, 0, 32);
|
||||||
do
|
do {
|
||||||
{
|
if (idx == 0) {
|
||||||
if (idx == 0)
|
readI2C(buff);
|
||||||
{
|
delay(I2C_DELAY);
|
||||||
readI2C(buff);
|
|
||||||
delay(I2C_DELAY);
|
|
||||||
}
|
}
|
||||||
c = buff[idx];
|
c = buff[idx];
|
||||||
idx++;
|
idx++;
|
||||||
idx %= 32;
|
idx %= 32;
|
||||||
}
|
} while ((uint8_t)c != 0xFF);
|
||||||
while ((uint8_t) c != 0xFF);
|
|
||||||
|
|
||||||
pinMode(2, INPUT);
|
pinMode(2, INPUT);
|
||||||
attachInterrupt(digitalPinToInterrupt(2), ppsHandler, RISING);
|
attachInterrupt(digitalPinToInterrupt(2), ppsHandler, RISING);
|
||||||
|
@ -465,13 +451,13 @@ void setup() {
|
||||||
LMIC_setLinkCheckMode(0);
|
LMIC_setLinkCheckMode(0);
|
||||||
LMIC_setDrTxpow(DR_SF8, 20);
|
LMIC_setDrTxpow(DR_SF8, 20);
|
||||||
// Sub-band 2 - Helium Network
|
// Sub-band 2 - Helium Network
|
||||||
LMIC_selectSubBand(1); // zero indexed
|
LMIC_selectSubBand(1); // zero indexed
|
||||||
|
|
||||||
// Start job (sending automatically starts OTAA too)
|
// Start job (sending automatically starts OTAA too)
|
||||||
do_send(&sendjob);
|
do_send(&sendjob);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
os_runloop_once();
|
os_runloop_once();
|
||||||
readGPS();
|
readGPS();
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue