kopia lustrzana https://github.com/PiInTheSky/lora-gateway
V1.8.30 - Added ability to connect to hab.link server for responsive custom dashboards
rodzic
ed91ad1f1f
commit
372b0dcd5b
|
@ -79,6 +79,8 @@ The global options are:
|
|||
|
||||
EnableSSDV=<Y/N>. Enables uploading of SSDV image packets to the SSDV server.
|
||||
|
||||
EnableHABLink=<Y/N>. Enables uploading of telemetry packets to the hab.link server.
|
||||
|
||||
JPGFolder=<folder>. Tells the gateway where to save local JPEG files built from incoming SSDV packets.
|
||||
|
||||
LogTelemetry=<Y/N>. Enables logging of telemetry packets (ASCII only at present) to telemetry.txt.
|
||||
|
|
22
gateway.c
22
gateway.c
|
@ -33,6 +33,7 @@
|
|||
#include "ssdv.h"
|
||||
#include "ftp.h"
|
||||
#include "habitat.h"
|
||||
#include "hablink.h"
|
||||
#include "network.h"
|
||||
#include "network.h"
|
||||
#include "global.h"
|
||||
|
@ -45,7 +46,7 @@
|
|||
#include "udpclient.h"
|
||||
#include "lifo_buffer.h"
|
||||
|
||||
#define VERSION "V1.8.29"
|
||||
#define VERSION "V1.8.30"
|
||||
bool run = TRUE;
|
||||
|
||||
// RFM98
|
||||
|
@ -1059,6 +1060,11 @@ int ProcessTelemetryMessage(int Channel, received_t *Received)
|
|||
}
|
||||
}
|
||||
|
||||
if (Config.EnableHablink)
|
||||
{
|
||||
SetHablinkSentence(startmessage);
|
||||
}
|
||||
|
||||
tm = localtime( &Received->Metadata.Timestamp );
|
||||
LogMessage("%02d:%02d:%02d Ch%d: %s%s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, Channel, startmessage, Repeated ? " (repeated)" : "");
|
||||
|
||||
|
@ -1902,6 +1908,7 @@ 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);
|
||||
|
||||
// Enable telemetry logging
|
||||
RegisterConfigBoolean(MainSection, -1, "LogTelemetry", &Config.EnableTelemetryLogging, NULL);
|
||||
|
@ -2478,7 +2485,7 @@ int main( int argc, char **argv )
|
|||
int ch;
|
||||
int LoopPeriod, MSPerLoop;
|
||||
int Channel;
|
||||
pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, ServerThread, TelnetThread, ListenerThread, DataportThread, ChatportThread;
|
||||
pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, HablinkThread, ServerThread, TelnetThread, ListenerThread, DataportThread, ChatportThread;
|
||||
struct TServerInfo JSONInfo, TelnetInfo, DataportInfo, ChatportInfo;
|
||||
|
||||
atexit(bye);
|
||||
|
@ -2573,6 +2580,15 @@ int main( int argc, char **argv )
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.EnableHablink)
|
||||
{
|
||||
if (pthread_create (&HablinkThread, NULL, HablinkLoop, NULL))
|
||||
{
|
||||
fprintf( stderr, "Error creating Hablink thread\n" );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.ServerPort > 0)
|
||||
{
|
||||
|
@ -2763,7 +2779,7 @@ int main( int argc, char **argv )
|
|||
char Message[200];
|
||||
|
||||
Seconds = 0;
|
||||
sprintf(Message, "GATEWAY:HOST=%s,IP=%s,VER=%s%s\n", Hostname(), GetIPAddress(), VERSION, ChannelInfo());
|
||||
sprintf(Message, "GATEWAY:HOST=%s,IP=%s,VER=%s,CALLSIGN=%s%s\n", Hostname(), GetIPAddress(), VERSION, Config.Tracker, ChannelInfo());
|
||||
UDPSend(Message, Config.UDPPort);
|
||||
}
|
||||
}
|
||||
|
|
1
global.h
1
global.h
|
@ -112,6 +112,7 @@ struct TConfig
|
|||
|
||||
int EnableHabitat;
|
||||
int EnableSSDV;
|
||||
int EnableHablink;
|
||||
int EnableTelemetryLogging;
|
||||
int EnablePacketLogging;
|
||||
int CallingTimeout;
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
#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);
|
||||
|
||||
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)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
|
||||
{
|
||||
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 ...\n");
|
||||
|
||||
while (sockfd < 0)
|
||||
{
|
||||
sockfd = ConnectSocket("52.56.152.45", 8887);
|
||||
|
||||
if (sockfd >= 0)
|
||||
{
|
||||
LogMessage("Connected to hab.link\n");
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
void *HablinkLoop( void *some_void_ptr );
|
||||
void SetHablinkSentence(char *tmp);
|
|
@ -115,6 +115,6 @@ NetworkLoop( void *some_void_ptr )
|
|||
// LogMessage("No network :-(\n");
|
||||
}
|
||||
|
||||
sleep( 5 );
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue