Skip to content

Exp #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: exp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c21215d
clean and update
roblad Oct 22, 2016
65ee5e9
clean and update
roblad Oct 22, 2016
1c0b1c6
Movment les then 10m blocker - not sending
roblad Oct 23, 2016
3c41294
Movment 10 m and change vars of gps_data to pointers, remove watchdo…
roblad Oct 23, 2016
205c4f5
Remove watchdog reset
roblad Oct 23, 2016
ebc414e
change mqtt server and description - private server
roblad Oct 27, 2016
c31ec6c
added AT command function and tuning connection
roblad Oct 27, 2016
2efd46d
added function for movement and heartbit and tunning connection, hang…
roblad Oct 27, 2016
7af5d26
moved some parameters to eeprom keep alive mqtt server open
roblad Oct 29, 2016
c0134f2
moved some setting to eeprom keepalive conection to mqtt
roblad Oct 29, 2016
445e7d2
small changes with heartbit - better keep alive
roblad Oct 30, 2016
19cd720
reconect added and changes for delays
roblad Nov 6, 2016
56ca798
roolback to variables delays change
roblad Nov 6, 2016
16204ba
own server added
roblad Nov 6, 2016
9dd651b
last but not well - 714 byte ram - not help
roblad Nov 9, 2016
c2fced4
last but not well - 714 byte ram - not help
roblad Nov 9, 2016
34edaa1
many changes added auto reset - pin 4 soldering needed
roblad Nov 15, 2016
7942a6e
many changes reset added
roblad Nov 15, 2016
aa55319
_SS_MAX_RX_BUFF to 128
roblad Nov 15, 2016
fc04699
cleaning and changes for reseting - quicker
roblad Nov 16, 2016
199ad86
cleaning - smal changes
roblad Nov 16, 2016
665ff66
delay change
roblad Nov 16, 2016
50b5b48
final version
roblad Nov 26, 2016
0caa351
final version
roblad Nov 26, 2016
7a3cb32
final version
roblad Nov 26, 2016
9159afd
Update fonahelper.cpp
roblad Nov 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions arduino/gps-tracker2/config.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
#define GSM_APN "internet"
#define GSM_USERNAME ""
#define GSM_PASSWORD ""
/*define mqtt brocker
* https://customer.cloudmqtt.com/login
* register your server (for free 10 connections allowed)
* set direct access to server - config as standard owntrack config
* create user i.e. piesek
* create topic for user RW access owntracks/#
*
*
*/
//soft serial buffer
#define _SS_MAX_RX_BUFF 128
//gsm
#define GSM_APN "internet"
#define GSM_USERNAME ""
#define GSM_PASSWORD ""

#define AIO_SERVER "broker.mqttdashboard.com"
#define AIO_SERVERPORT 1883
// #define AIO_USERNAME ""
// #define AIO_PASSWORD ""

#define TOPIC "owntracks/piesek/yasmina"
#define TID "yb" // "tracker-ID which is used by the auto-faces feature to display, say, initials of a user."
#define SPEED_TR 2 // bellow that number = 0

#define DELAY 10 // seconds
//#define AIO_SERVER "m20.cloudmqtt.com"
//#define AIO_SERVER "broker.mqttdashboard.com"
//#define AIO_SERVER "broker.hivemq.com"
#define AIO_SERVER "xxx.xxx.xxx.xxx"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "piesek"
#define AIO_PASSWORD "xxxxxxxxx"
#define TOPIC "owntracks/piesek/yasmina"
#define TID "yb" // "tracker-ID which is used by the auto-faces feature to display, say, initials of a user."
#define SPEED_TR 3 // bellow that number = 0
#define HEARTBIT 120 // there ic multiply by DELAY and sending heartbit - set for every 30 min when movement trying is 5 sec.
#define DELAY 10 // seconds + ~5
#define MOVEMENT 50.0 //metters moved to report
//#define DEBUG
190 changes: 120 additions & 70 deletions arduino/gps-tracker2/fonahelper.cpp
Original file line number Diff line number Diff line change
@@ -1,128 +1,178 @@
#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
#include "config.h"
#include "Adafruit_FONA.h"
#include <SoftwareSerial.h>


#define halt(s) { Serial.println(F( s )); while(1); }
/*
//prog mem helper - change buffer size for topic if needed
const char stringBuffer[30];
const char* getString(const char* str[30]) {
strcpy_P(stringBuffer, (const char*)str);
delay(50);
return stringBuffer;
}
*/


extern Adafruit_FONA fona;
extern SoftwareSerial fonaSS;

char utime[14];
int YY;
int MM;
int DD;
int hh;
int mm;
int ss;
//extern SoftwareSerial *fonaSerial;


// flags
byte gps_enabled = 0;


boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *username, const __FlashStringHelper *password) {
Watchdog.reset();


//Serial.println(F("Initializing FONA....(May take 3 seconds)"));

//fonaSS.begin(*fonaSerial); // if you're using software serial
fonaSS.begin(9600);
while (!fonaSS);
fonaSS.begin(9800);
delay(50);


if (! fona.begin(fonaSS)) { // can also try fona.begin(Serial1)
delay(50);
#ifdef DEBUG
Serial.println(F("Couldn't find FONA"));
delay(50);
#endif
return false;
} else {

// to test
}
fonaSS.println("AT+CMEE=2");
//Serial.println(F("FONA is OK"));
Watchdog.reset();
// Serial.println(F("Checking for network..."));

while (!fonaSS);


byte net =0;
while (fona.getNetworkStatus() != 1) {
delay(500);
#ifdef DEBUG
Serial.println(F("Waiting for network ..."));
#endif
delay(15000);
while ( !fonaSS);
net++;
if (net == 20) {
fonaSS.end();
asm volatile ( "jmp 0");
}
}

Watchdog.reset();
delay(5000); // wait a few seconds to stabilize connection
Watchdog.reset();

//delay(20000); // wait a few seconds to stabilize connection

fona.setGPRSNetworkSettings(apn, username, password);

//Serial.println(F("Disabling GPRS"));
while (!fonaSS);
fona.enableGPRS(false);

Watchdog.reset();
delay(5000); // wait a few seconds to stabilize connection
Watchdog.reset();

delay(500); // wait a few seconds to stabilize connection
#ifdef DEBUG
Serial.println(F("Enabling GPRS"));
delay(50);
#endif
while (!fonaSS);
if (!fona.enableGPRS(true)) {
//Serial.println(F("Failed to turn GPRS on"));
#ifdef DEBUG
Serial.println(F("Failed to turn GPRS on"));
delay(50);
#endif
return false;
}

Watchdog.reset();
while (!fonaSS);
fona.enableRTC(1);

return true;
}


boolean GPS() {

if (gps_enabled == 0 ) {
//Serial.println(F("Enabling GPS"));
if (!fona.enableGPS(true)) {
Serial.println(F("Failed to turn GPS on"));
#ifdef DEBUG
Serial.println(F("Enabling GPS"));
delay(50);
#endif
while ( !fonaSS);
fona.enableGPS(false);
delay(500);
while ( !fonaSS);
if(!fona.enableGPS(true)) {
#ifdef DEBUG
Serial.println(F("Failed to turn GPS on"));
delay(50);
#endif
return false;
}
else {
} else {
gps_enabled = 1;
delay(10000);
}
}

Watchdog.reset();
delay(5000); // wait a few seconds to stabilize connection
Watchdog.reset();

Watchdog.reset();
//Serial.println(F("Looking for satelites"));
byte stat;
while ( !fonaSS);
stat = fona.GPSstatus();
delay(500);
if (stat < 0 or stat == 0 or stat == 1) {
#ifdef DEBUG
Serial.println(F("Not fixed!"));
delay(50);
#endif
return false;
}
if (stat >= 2) {

}
if (stat >= 2) {
#ifdef DEBUG
Serial.println(F("GPS Fixed"));
}
delay(50);
#endif
return true;
} else {
return false;
}

Watchdog.reset();

return true;
return false;
}


void GPS_Data(float *fdata, int *idata) {



float latitude, longitude, speed_kph, heading, altitude;
boolean gps_success = fona.getGPS(&latitude, &longitude, &altitude, &speed_kph, &heading, &utime[0]);
sscanf(utime,"%04d%02d%02d%02d%02d%02d",&YY,&MM,&DD,&hh,&mm,&ss);


// put data into array
fdata[0] = latitude;
fdata[1] = longitude;
fdata[2] = speed_kph;
fdata[3] = altitude;
fdata[4] = heading;
idata[0] = hh;
idata[1] = mm;
idata[2] = ss;
idata[3] = DD;
idata[4] = MM;
idata[5] = YY;
char utime[14];
//int YY;
//int MM;
//int DD;
//int hh;
//int mm;
//int ss;
float latitude, longitude, speed_kph,cog;
//, speed_kph, heading, altitude;
//boolean gps_success = fona.getGPS(&fdata[0], &fdata[1], &fdata[3], &fdata[2], &fdata[4], &utime[0]);
while (!fonaSS);
boolean gps_success = fona.getGPS(&latitude,&longitude, &fdata[3], &speed_kph, &cog, &utime[0]);
delay(50);
//sscanf(utime,"%04d%02d%02d%02d%02d%02d",&YY,&MM,&DD,&hh,&mm,&ss);
sscanf(utime,"%04d%02d%02d%02d%02d%02d",&idata[5],&idata[4],&idata[3],&idata[0],&idata[1],&idata[2]);
delay(50);
//idata[0] = hh;
//idata[1] = mm;
//idata[2] = ss;
//idata[3] = DD;
//idata[4] = MM;
//idata[5] = YY;


if (&gps_success) {
//delete utime;

fdata[0]=latitude;
fdata[1]=longitude;
fdata[2]=speed_kph;
fdata[4]=cog;
//sendATcommand("AT+CGATT=1",1000);
delay(50);

return &fdata;

}
}

Loading