summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorkutayboz <kutayboz@gmail.com>2023-06-13 01:17:59 +0300
committerkutayboz <kutayboz@gmail.com>2023-06-13 01:17:59 +0300
commitfbd07ec5acaed65b892e0a1c144eb779d6d95ddc (patch)
treebf64c93d06e0a9de2d594f99e8b943f6672bf8a5 /src/main.c
parent0cf6be4cd144b01f91049891388c3cd063f43c9f (diff)
downloadcelnetmon-fbd07ec5acaed65b892e0a1c144eb779d6d95ddc.tar.gz
Added GNSS functionality
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 3dd2f56..236c333 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,73 +36,102 @@ int main(int argc, char **argv) {
else if (0 == strcmp(argv[1], "--init")) {
+ printf("Powering on\n");
if (0 != powerOn(PATH_TO_SERIAL_PORT, PATH_TO_GPIO_CHIP, PIN_NUM_STATUS,
PIN_NUM_PWR_KEY)) {
printf("Error powering the module on\n");
return 1;
}
+ printf("Initiating GNSS\n");
+ if (0 != initGNSS(PATH_TO_SERIAL_PORT)) {
+ printf("Error initiating GNSS\n");
+ return 1;
+ }
+
+ printf("Configuring the network settings for DNA public network\n");
if (0 != cfgPublicNetwork(PATH_TO_SERIAL_PORT)) {
printf("Error setting public network configuration\n");
return 1;
}
+ printf("Waiting for establishing network connection\n");
if (0 != waitForNetwork(PATH_TO_SERIAL_PORT, 120)) {
printf("Error while waiting for network\n");
return 1;
}
+ printf("Initialization complete\n");
return 0;
}
else if (0 == strcmp(argv[1], "--stop")) {
+
+ printf("Stopping GNSS\n");
+ if (0 != stopGNSS(PATH_TO_SERIAL_PORT)) {
+ printf("Error stopping GNSS\n");
+ }
+
+ printf("Disconnecting MQTT\n");
if (0 != mqttDisc(PATH_TO_SERIAL_PORT)) {
printf("Could not disconnect MQTT\n");
}
+
+ printf("Powering off\n");
if (0 != powerOff(PATH_TO_SERIAL_PORT, PATH_TO_GPIO_CHIP, PIN_NUM_STATUS,
PIN_NUM_PWR_KEY)) {
printf("Error powering the module off\n");
return 1;
}
+ printf("Power off complete\n");
return 0;
}
else if (0 == strcmp(argv[1], "--netinfo-pub")) {
networkData *nD = malloc(sizeof(networkData));
+ printf("Obtaining network info\n");
initNetworkData(nD);
- gatherData(nD, PATH_TO_SERIAL_PORT);
+ if (gatherData(nD, PATH_TO_SERIAL_PORT) != 0) {
+ printf("Failed to gather network info\n");
+ goto netinfopubFail;
+ }
printf("Connecting to the MQTT broker\n");
if (0 != mqttConn(PATH_TO_SERIAL_PORT, "io.adafruit.com", 8883, "kboz",
"aio_lvhz87FJ0rIlidH8g30V5mQ7FK7s")) {
printf("Error connecting MQTT\n");
- return 1;
+ goto netinfopubFail;
}
/* if (0 != mqttConn(PATH_TO_SERIAL_PORT,
"29038f72a9d84f18940e0d44daffa687.s2.eu.hivemq.cloud",
8883, "rpi5gtn", "Raspi132.")) {
printf("Error connecting MQTT\n");
- return 1;
+ goto netinfopubFail;
} */
printf("Publishing network information\n");
if (0 != mqttPubNetData(PATH_TO_SERIAL_PORT, *nD)) {
printf("Error publishing to MQTT server\n");
- return 1;
+ goto netinfopubFail;
}
printf("Disconnecting from the MQTT broker\n");
if (0 != mqttDisc(PATH_TO_SERIAL_PORT)) {
printf("Could not disconnect MQTT\n");
- return 1;
+ goto netinfopubFail;
}
- printf("Done\n");
+ printf("Network info published\n");
freeNetworkData(nD);
free(nD);
return 0;
+
+ netinfopubFail:
+ freeNetworkData(nD);
+ free(nD);
+ return 1;
}
else {