Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Akene-sigfox-projet-iot-tracker SerialGPS_IOT_tracker SoftSerial mbed
Diff: main.cpp
- Revision:
- 1:3390618a8252
- Parent:
- 0:8a9b5024eda9
diff -r 8a9b5024eda9 -r 3390618a8252 main.cpp
--- a/main.cpp Wed Feb 08 16:48:13 2017 +0000
+++ b/main.cpp Tue Feb 14 16:27:44 2017 +0000
@@ -1,13 +1,80 @@
#include "mbed.h"
#include "Akene.h"
+#include "SerialGPS.h"
+#include "math.h"
-AnalogIn analog_value(A0);
+Serial pc(USBTX, USBRX); // tx, rx
+SerialGPS gps(PA_9,PA_10); // tx, rx
+
+void cbfunc_log(char *s) {
+
+}
+
+/**
+ * A callback function for GGA.
+ *
+ * GGA - Global Positioning System Fixed Data.
+ */
+ float latitude = 0.0;
+ float longitude = 0.0;
+ int flag = 0;
+void cbfunc_gga(SerialGPS::gps_gga_t *p) {
+
+ pc.printf("%02d:%02d:%02d(P%d,S%d)\r\n", p->hour, p->min, p->sec, p->position_fix, p->satellites_used);
+
+ pc.printf("%c=%10.4f\r\n", p->ns, p->latitude);
+
+ pc.printf("%c=%10.4f\r\n", p->ew, p->longitude);
+
+ latitude = (float) p->latitude;
+ longitude = (float) p->longitude;
+ flag = 1;
+
+}
+
+void cbfunc_gsa(SerialGPS::gps_gsa_t *p) {
+
+ pc.printf("SEL:%c FIX:%d\r\n", p->selmode, p->fix);
+
+}
+void cbfunc_gsv(SerialGPS::gps_gsv_t *p) {
-DigitalOut led(LED1);
+ pc.printf("Satellites:%2d\r\n", p->satcnt);
+
+}
+void cbfunc_rmc(SerialGPS::gps_rmc_t *p) {
+
+ pc.printf("%02d:%02d:%02d(%c)\r\n", p->hour, p->min, p->sec, p->status);
+
+}
+
+/**
+ * Entry point.
+ */
+
+int main() {
+
+ pc.baud(9600);
+ pc.printf("beginn\n\r");
+ // GPS set
+ wait(0.5);
+ SerialGPS::gps_callback_t cb;
+ cb.cbfunc_log = cbfunc_log;
+ cb.cbfunc_gga = cbfunc_gga;
+ cb.cbfunc_gsa = cbfunc_gsa;
+ cb.cbfunc_gsv = cbfunc_gsv;
+ cb.cbfunc_rmc = cbfunc_rmc;
+ gps.attach(&cb);
+
+
+ //Wait for proper longitude and latitude
+ while( flag == 0) {
+ gps.processing();
+ //wait(0.5);
+ }
-
-int main() {
+ //sigfox
char tmp[8];
printf("\ntest envoie sigfox\n");
@@ -15,39 +82,41 @@
Akene.begin();
printf("begin ok");
- //while(1) {
- while (!Akene.isReady()) {
- printf("Modem not ready");
- wait(1);
- }
+
+ while (!Akene.isReady()) {
+ printf("Modem not ready");
+ wait(1);
+ }
+
+ // DATA ENCODING :
- // Mettre latitude à envoyer dans :
- float float_variable0 = 1.11;
- char bytes_array0[4];
- // Mettre longitude à envoyer dans :
- float float_variable1 = 1.1333;
- char bytes_array1[4];
-
- *((float *)bytes_array0) = float_variable0;
- *((float *)bytes_array1) = float_variable1;
-
- char bytes_array_final [8];
- int i;
- for ( i =0;i<8;i++){
- if (i<4){
- bytes_array_final[i]=bytes_array0[i];
-
- }
- else {
- bytes_array_final[i]=bytes_array1[i-4];
- }
+ // Mettre latitude à envoyer dans :
+ float float_variable0 = longitude;
+ char bytes_array0[4];
+ // Mettre longitude à envoyer dans :
+ float float_variable1 = latitude;
+ char bytes_array1[4];
+
+ *((float *)bytes_array0) = float_variable0;
+ *((float *)bytes_array1) = float_variable1;
+
+ char bytes_array_final [8];
+ int i;
+ for ( i =0;i<8;i++){
+ if (i<4){
+ bytes_array_final[i]=bytes_array0[i];
+
}
-
-
- // Send in the mighty internet!
- printf("Sending");
+ else {
+ bytes_array_final[i]=bytes_array1[i-4];
+ }
+ }
+
+ // DATA SENDING :
+ printf("Sending");
- Akene.send(&bytes_array_final,sizeof(bytes_array_final));
-
-
+ Akene.send(&bytes_array_final,sizeof(bytes_array_final));
+ wait(10);
+
+
}