mirror of
https://github.com/eddyem/small_tel.git
synced 2026-06-19 10:26:25 +03:00
fixed some bugs, check @ real system
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -fPIC -DEBUG
|
||||
CFLAGS = -Wall -Wextra -fPIC
|
||||
#-DEBUG
|
||||
LDFLAGS = -lrt -pthread -lusefull_macros
|
||||
|
||||
all: weather_daemon libweather.so weather_clt_example chkweather
|
||||
all: weather_proxy libweather.so weather_clt_example chkweather
|
||||
|
||||
weather_daemon: weather_daemon.o
|
||||
weather_proxy: weather_daemon.o
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
weather_clt_example: weather_clt_example.o
|
||||
@@ -32,8 +33,10 @@ chkweather.o: chkweather.c libweather.so
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
clean:
|
||||
rm -f *.o weather_daemon libweather.so libweather.a weather_clt_example
|
||||
rm -f *.o weather_proxy chkweather libweather.so libweather.a weather_clt_example
|
||||
|
||||
install:
|
||||
cp libweather.so /usr/local/lib/
|
||||
cp weather_data.h /usr/local/include/
|
||||
cp chkweather weather_proxy /usr/local/bin
|
||||
ldconfig
|
||||
|
||||
@@ -27,10 +27,11 @@ int main() {
|
||||
struct tm *T = localtime(&wd.last_update);
|
||||
strftime(strt, 63, "%F %T", T);
|
||||
printf("Windmax=%.1f\nRain=%d\nClouds=%.1f\nWind=%.1f\nExttemp=%.1f\n"
|
||||
"Pres=%.1f\nHumid=%.1f\nMeteo=local\nForceOFF=%d\n",
|
||||
"Pres=%.1f\nHumid=%.1f\nMeteo=local\nForceOFF=%d\nWeather=%d\nWeatherTime=%d [%s]\n",
|
||||
wd.windmax, wd.rain, wd.clouds, wd.wind, wd.exttemp,
|
||||
wd.pressure, wd.humidity, wd.forceoff);
|
||||
wd.pressure, wd.humidity, wd.forceoff, (int)wd.weather, (int)wd.last_update, strt);
|
||||
if(!wd.forceoff) errcode = wd.weather;
|
||||
if(time(NULL) - wd.last_update > 30) errcode = 3;
|
||||
}else{
|
||||
fprintf(stderr, "Failed to get weather data\n");
|
||||
}
|
||||
|
||||
@@ -280,13 +280,13 @@ static void run_daemon(){
|
||||
|
||||
while(running){
|
||||
time_t tnow = time(NULL);
|
||||
int req = -1;
|
||||
int req = -1, goterr = 0;
|
||||
if(sock) req = request_weather_data(sock);
|
||||
if(req == -1){
|
||||
int diff = tnow - lastert;
|
||||
DBG("diff = %d", diff);
|
||||
if(diff > RECONN_TMOUT){ // try to reconnect
|
||||
LOGERR("Failed to request weather data, retry");
|
||||
if(!goterr){ LOGERR("Failed to request weather data, retry"); goterr = 1; }
|
||||
if(sock) sl_sock_delete(&sock);
|
||||
if(!(sock = sl_sock_run_client(stype, G.node, 4096))){
|
||||
new_data.weather = WEATHER_TERRIBLE; // no connection to weather server, don't allow to open
|
||||
@@ -298,6 +298,7 @@ static void run_daemon(){
|
||||
}
|
||||
}
|
||||
}else if(req == 0) lastert = tnow;
|
||||
else goterr = 0;
|
||||
|
||||
while(sl_sock_readline(sock, line, 255) > 0){
|
||||
DBG("Parse '%s'", line);
|
||||
|
||||
Reference in New Issue
Block a user