Avoid uploading user lat/lon unless it's been set

pull/72/head
Dave Akerman 2022-09-30 15:15:23 +01:00
rodzic 3502e689f5
commit 85016c6755
4 zmienionych plików z 34 dodań i 172 usunięć

Wyświetl plik

@ -35,7 +35,6 @@
#include "habitat.h"
#include "sondehub.h"
#include "mqtt.h"
#include "hablink.h"
#include "network.h"
#include "network.h"
#include "global.h"
@ -1172,11 +1171,6 @@ int ProcessTelemetryMessage(int Channel, received_t *Received)
}
}
if (Config.EnableHablink && Config.HablinkAddress[0])
{
SetHablinkSentence(startmessage);
}
if (Config.EnableSondehub)
{
SetSondehubSentence(Channel, startmessage);
@ -2067,12 +2061,9 @@ void LoadConfigFile(void)
// Enable uploads
RegisterConfigBoolean(MainSection, -1, "EnableHabitat", &Config.EnableHabitat, NULL);
RegisterConfigBoolean(MainSection, -1, "EnableSSDV", &Config.EnableSSDV, NULL);
RegisterConfigBoolean(MainSection, -1, "EnableHablink", &Config.EnableHablink, NULL);
RegisterConfigBoolean(MainSection, -1, "EnableSondehub", &Config.EnableSondehub, NULL);
RegisterConfigString(MainSection, -1, "HablinkAddress", Config.HablinkAddress, sizeof(Config.HablinkAddress), NULL);
// Enable telemetry logging
// Enable telemetry logging
RegisterConfigBoolean(MainSection, -1, "LogTelemetry", &Config.EnableTelemetryLogging, NULL);
// Enable packet logging
@ -2665,7 +2656,7 @@ int main( int argc, char **argv )
int ch;
int LoopPeriod, MSPerLoop;
int Channel;
pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, HablinkThread, SondehubThread, ServerThread, TelnetThread, ListenerThread, DataportThread, ChatportThread, MQTTThread;
pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, SondehubThread, ServerThread, TelnetThread, ListenerThread, DataportThread, ChatportThread, MQTTThread;
struct TServerInfo JSONInfo, TelnetInfo, DataportInfo, ChatportInfo;
atexit(bye);
@ -2782,15 +2773,6 @@ int main( int argc, char **argv )
}
}
if (Config.EnableHablink && Config.HablinkAddress[0])
{
if (pthread_create (&HablinkThread, NULL, HablinkLoop, NULL))
{
fprintf( stderr, "Error creating Hablink thread\n" );
return 1;
}
}
if (Config.EnableSondehub)
{
if (pthread_create (&SondehubThread, NULL, SondehubLoop, NULL))

132
hablink.c
Wyświetl plik

@ -1,132 +0,0 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include "hablink.h"
#include "global.h"
char HablinkSentence[256];
void SetHablinkSentence(char *tmp)
{
strcpy(HablinkSentence, tmp);
}
void UploadSentence(int sockfd, char *Sentence)
{
char Message[300];
// Create message to upload
// sprintf(Message, "POSITION:CALLSIGN=%s,SENTENCE=%s\n", Config.Tracker, Sentence);
sprintf(Message, "POSITION:SENTENCE=%s\n", Sentence);
write(sockfd, Message, strlen(Message));
}
void UploadListener(int sockfd)
{
char Message[100];
// Create message to upload
sprintf(Message, "LISTENER:TYPE=LoRa Gateway,VERSION=%s,CALLSIGN=%s\n", Config.Version, Config.Tracker);
write(sockfd, Message, strlen(Message));
}
int ConnectSocket(char *Host, int Port)
{
int sockfd;
struct sockaddr_in serv_addr;
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
return -1;
}
memset(&serv_addr, '0', sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(Port);
if (inet_pton(AF_INET, Host, &serv_addr.sin_addr) <=0)
{
close(sockfd);
return -1;
}
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
close(sockfd);
return -1;
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
return sockfd;
}
int StillConnected(int sockfd)
{
char buf[1];
int Count;
Count = read(sockfd, buf, 1);
return Count != 0;
}
void *HablinkLoop( void *vars )
{
int sockfd;
sockfd = -1;
while (1)
{
if (sockfd < 0)
{
LogMessage("Connecting to hab.link (%s:%d)...\n", Config.HablinkAddress, 8887);
while (sockfd < 0)
{
sockfd = ConnectSocket(Config.HablinkAddress, 8887);
if (sockfd >= 0)
{
LogMessage("Connected to hab.link\n");
UploadListener(sockfd);
}
else
{
sleep(1);
}
}
}
// Check still connected
if (!StillConnected(sockfd))
{
LogMessage("Disconnected from hab.link\n");
close(sockfd);
sockfd = -1;
}
if ((sockfd >= 0) && HablinkSentence[0])
{
UploadSentence(sockfd, HablinkSentence);
HablinkSentence[0] = '\0';
}
usleep(100000);
}
}

Wyświetl plik

@ -1,2 +0,0 @@
void *HablinkLoop( void *some_void_ptr );
void SetHablinkSentence(char *tmp);

Wyświetl plik

@ -100,8 +100,6 @@ int UploadJSONToServer(char *url, char *json)
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp);
if (http_resp == 200)
{
// Everything performing nominally (even if we didn't successfully insert this time)
// LogError("200 response to:", json);
result = true;
}
else if (http_resp == 400)
@ -113,6 +111,7 @@ int UploadJSONToServer(char *url, char *json)
else
{
LogMessage("Unexpected HTTP response %ld for URL '%s'\n", http_resp, url);
LogError("400 response to:", json);
result = false;
}
}
@ -227,7 +226,7 @@ void ExtractFields(char *Telemetry, char *ExtractedFields)
int UploadSondehubPosition(int Channel)
{
char url[200];
char json[1000], now[32], doc_time[32], ExtractedFields[256];
char json[1000], now[32], doc_time[32], ExtractedFields[256], uploader_position[256];
time_t rawtime;
struct tm *tm, *doc_tm;
@ -243,6 +242,21 @@ int UploadSondehubPosition(int Channel)
// Find field list and extract fields
ExtractFields(SondehubPayloads[Channel].Telemetry, ExtractedFields);
if ((Config.latitude >= -90) && (Config.latitude <= 90) && (Config.longitude >= -180) && (Config.longitude <= 180))
{
sprintf(uploader_position, "\"uploader_position\": ["
" %.3lf," // Listener Latitude
" %.3lf," // Listener Longitude
" %.0lf" // Listener Altitude
"],",
Config.latitude, Config.longitude, Config.altitude
);
}
else
{
uploader_position[0] = '\0';
}
// Create json as required by sondehub-amateur
sprintf(json, "[{\"software_name\": \"LoRa Gateway\"," // Fixed software name
"\"software_version\": \"%s\"," // Version
@ -259,11 +273,7 @@ int UploadSondehubPosition(int Channel)
"\"rssi\": %d," // RSSI
"\"raw\": \"%s\"," // Sentence
"%s"
"\"uploader_position\": ["
" %.3lf," // Listener Latitude
" %.3lf," // Listener Longitude
" %.0lf" // Listener Altitude
"],"
"%s"
"\"uploader_antenna\": \"%s\""
"}]",
Config.Version, Config.Tracker, now,
@ -274,7 +284,8 @@ int UploadSondehubPosition(int Channel)
SondehubPayloads[Channel].PacketSNR, SondehubPayloads[Channel].PacketRSSI,
SondehubPayloads[Channel].Telemetry,
ExtractedFields,
Config.latitude, Config.longitude, Config.altitude, Config.antenna);
uploader_position,
Config.antenna);
// Set the URL that is about to receive our PUT
strcpy(url, "https://api.v2.sondehub.org/amateur/telemetry");
@ -356,17 +367,20 @@ void *SondehubLoop( void *vars )
}
}
if (--ListenerCountdown <= 0)
if ((Config.latitude >= -90) && (Config.latitude <= 90) && (Config.longitude >= -180) && (Config.longitude <= 180))
{
if (UploadListenerToSondehub())
if (--ListenerCountdown <= 0)
{
LogMessage("Uploaded listener info to Sondehub/amateur\n");
ListenerCountdown = 216000; // Every 6 hours
}
else
{
LogMessage("Failed to upload listener info to Sondehub/amateur\n");
ListenerCountdown = 600; // Try again in 1 minute
if (UploadListenerToSondehub())
{
LogMessage("Uploaded listener info to Sondehub/amateur\n");
ListenerCountdown = 216000; // Every 6 hours
}
else
{
LogMessage("Failed to upload listener info to Sondehub/amateur\n");
ListenerCountdown = 600; // Try again in 1 minute
}
}
}