kopia lustrzana https://github.com/PiInTheSky/lora-gateway
Added client port; added timestamps
rodzic
06839a2eec
commit
680f40496b
|
@ -0,0 +1,5 @@
|
|||
This file is placed here by pip to indicate the source was put
|
||||
here by pip.
|
||||
|
||||
Once this package is successfully installed this source code will be
|
||||
deleted (unless you remove this file).
|
BIN
gateway
BIN
gateway
Plik binarny nie jest wyświetlany.
32
gateway.c
32
gateway.c
|
@ -29,6 +29,7 @@
|
|||
#include "habitat.h"
|
||||
#include "network.h"
|
||||
#include "global.h"
|
||||
#include "server.h"
|
||||
|
||||
bool run = TRUE;
|
||||
|
||||
|
@ -538,7 +539,13 @@ void LogTelemetryPacket(char *Telemetry)
|
|||
|
||||
if ((fp = fopen("telemetry.txt", "at")) != NULL)
|
||||
{
|
||||
fprintf(fp, "%s\n", Telemetry);
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
|
||||
now = time(0);
|
||||
tm = localtime(&now);
|
||||
|
||||
fprintf(fp, "%02d:%02d:%02d - %s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, Telemetry);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
@ -722,6 +729,9 @@ void LoadConfigFile()
|
|||
Config.LoRaDevices[0].ActivityLED = ReadInteger(fp, "ActivityLED_0", 0, -1);
|
||||
Config.LoRaDevices[1].ActivityLED = ReadInteger(fp, "ActivityLED_1", 0, -1);
|
||||
|
||||
// Server Port
|
||||
Config.ServerPort = ReadInteger(fp, "ServerPort", 0, -1);
|
||||
|
||||
ReadString(fp, "ftpserver", Config.ftpServer, sizeof(Config.ftpServer), 0);
|
||||
ReadString(fp, "ftpUser", Config.ftpUser, sizeof(Config.ftpUser), 0);
|
||||
ReadString(fp, "ftpPassword", Config.ftpPassword, sizeof(Config.ftpPassword), 0);
|
||||
|
@ -1182,6 +1192,9 @@ void ProcessTelemetryMessage(int Channel, char *Message)
|
|||
|
||||
if (endmessage != NULL)
|
||||
{
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
|
||||
*endmessage = '\0';
|
||||
|
||||
LogTelemetryPacket(startmessage);
|
||||
|
@ -1190,7 +1203,11 @@ void ProcessTelemetryMessage(int Channel, char *Message)
|
|||
|
||||
ProcessLine(Channel, startmessage);
|
||||
|
||||
LogMessage("Ch %d: %s\n", Channel, startmessage);
|
||||
|
||||
now = time(0);
|
||||
tm = localtime(&now);
|
||||
|
||||
LogMessage("%02d:%02d:%02d Ch%d: %s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, Channel, startmessage);
|
||||
}
|
||||
|
||||
// DoPositionCalcs(Channel);
|
||||
|
@ -1334,7 +1351,7 @@ int main(int argc, char **argv)
|
|||
unsigned char Message[257], Command[200], Telemetry[100], *dest, *src;
|
||||
int Bytes, ch;
|
||||
uint32_t LoopCount[2];
|
||||
pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread;
|
||||
pthread_t SSDVThread, FTPThread, NetworkThread, HabitatThread, ServerThread;
|
||||
WINDOW * mainwin;
|
||||
int LEDCounts[2];
|
||||
|
||||
|
@ -1409,6 +1426,15 @@ int main(int argc, char **argv)
|
|||
fprintf(stderr, "Error creating Habitat thread\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Config.ServerPort > 0)
|
||||
{
|
||||
if (pthread_create(&ServerThread, NULL, ServerLoop, NULL))
|
||||
{
|
||||
fprintf(stderr, "Error creating server thread\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((Config.NetworkLED >= 0) && (Config.InternetLED >= 0))
|
||||
{
|
||||
|
|
19
gateway.txt
19
gateway.txt
|
@ -1,22 +1,23 @@
|
|||
tracker=M0RPI
|
||||
EnableHabitat=N
|
||||
tracker=M0RPI/M
|
||||
EnableHabitat=Y
|
||||
EnableSSDV=N
|
||||
LogTelemetry=N
|
||||
LogTelemetry=Y
|
||||
CallingTimeout=60
|
||||
ServerPort=6004
|
||||
|
||||
#NetworkLED=21
|
||||
#InternetLED=22
|
||||
#ActivityLED_0=23
|
||||
#ActivityLED_1=24
|
||||
|
||||
frequency_0=434.450
|
||||
#frequency_0=434.450
|
||||
mode_0=1
|
||||
DIO0_0=31
|
||||
DIO5_0=26
|
||||
AFC_0=Y
|
||||
|
||||
#frequency_1=434.450
|
||||
mode_1=1
|
||||
DIO0_1=6
|
||||
DIO5_1=5
|
||||
AFC_1=Y
|
||||
frequency_1=434.450
|
||||
mode_1=2
|
||||
DIO0_1=27
|
||||
DIO5_1=26
|
||||
AFC_1=N
|
||||
|
|
1
global.h
1
global.h
|
@ -49,6 +49,7 @@ struct TConfig
|
|||
struct TLoRaDevice LoRaDevices[2];
|
||||
int NetworkLED;
|
||||
int InternetLED;
|
||||
int ServerPort;
|
||||
};
|
||||
|
||||
extern struct TConfig Config;
|
||||
|
|
7
makefile
7
makefile
|
@ -1,5 +1,5 @@
|
|||
gateway: gateway.o urlencode.o base64.o habitat.o ssdv.o ftp.o network.o
|
||||
cc -o gateway gateway.o urlencode.o base64.o habitat.o ssdv.o ftp.o network.o -lm -lwiringPi -lwiringPiDev -lcurl -lncurses -lpthread
|
||||
gateway: gateway.o urlencode.o base64.o habitat.o ssdv.o ftp.o network.o server.o
|
||||
cc -o gateway gateway.o urlencode.o base64.o habitat.o ssdv.o ftp.o network.o server.o -lm -lwiringPi -lwiringPiDev -lcurl -lncurses -lpthread
|
||||
|
||||
gateway.o: gateway.c global.h
|
||||
gcc -c gateway.c
|
||||
|
@ -13,6 +13,9 @@ ssdv.o: ssdv.c ssdv.h global.h
|
|||
ftp.o: ftp.c ftp.h global.h
|
||||
gcc -c ftp.c
|
||||
|
||||
server.o: server.c server.h global.h
|
||||
gcc -c server.c
|
||||
|
||||
network.o: network.c network.h global.h
|
||||
gcc -c network.c
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h> // Standard input/output definitions
|
||||
#include <string.h> // String function definitions
|
||||
#include <unistd.h> // UNIX standard function definitions
|
||||
#include <fcntl.h> // File control definitions
|
||||
#include <errno.h> // Error number definitions
|
||||
#include <termios.h> // POSIX terminal control definitions
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "server.h"
|
||||
#include "global.h"
|
||||
|
||||
void *ServerLoop(void *some_void_ptr)
|
||||
{
|
||||
int listenfd = 0, connfd = 0;
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
char sendBuff[1025];
|
||||
time_t ticks;
|
||||
|
||||
listenfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
memset(&serv_addr, '0', sizeof(serv_addr));
|
||||
memset(sendBuff, '0', sizeof(sendBuff));
|
||||
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serv_addr.sin_port = htons(Config.ServerPort);
|
||||
|
||||
LogMessage("Listening on port %d\n", Config.ServerPort);
|
||||
|
||||
bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
|
||||
|
||||
listen(listenfd, 10);
|
||||
|
||||
while (1)
|
||||
{
|
||||
int port_closed;
|
||||
|
||||
connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
|
||||
|
||||
LogMessage("Connected to client\n");
|
||||
|
||||
for (port_closed=0; !port_closed; )
|
||||
{
|
||||
int Channel;
|
||||
// Build json
|
||||
// sprintf(sendBuff, "{\"class\":\"POSN\",\"time\":\"12:34:56\",\"lat\":54.12345,\"lon\":-2.12345,\"alt\":169}\r\n");
|
||||
|
||||
Channel = 1;
|
||||
sprintf(sendBuff, "{\"class\":\"POSN\",\"payload\":\"%s\",\"time\":\"%s\",\"lat\":%.5lf,\"lon\":%.5lf,\"alt\":%d,\"rate\":%.1lf}\r\n",
|
||||
Config.LoRaDevices[Channel].Payload,
|
||||
Config.LoRaDevices[Channel].Time,
|
||||
Config.LoRaDevices[Channel].Latitude,
|
||||
Config.LoRaDevices[Channel].Longitude,
|
||||
Config.LoRaDevices[Channel].Altitude,
|
||||
Config.LoRaDevices[Channel].AscentRate);
|
||||
|
||||
|
||||
if (send(connfd, sendBuff, strlen(sendBuff), MSG_NOSIGNAL) <= 0)
|
||||
{
|
||||
LogMessage("Disconnected from client\n");
|
||||
port_closed = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
close(connfd);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
void *ServerLoop(void *some_void_ptr);
|
Ładowanie…
Reference in New Issue