Browse Source

Added boolean for checking network connection

jancoow 9 năm trước cách đây
mục cha
commit
c683eae122
2 tập tin đã thay đổi với 11 bổ sung2 xóa
  1. 9 1
      network.c
  2. 2 1
      network.h

+ 9 - 1
network.c

@@ -20,18 +20,21 @@
 #include <arpa/inet.h>
 #include <pro/dhcp.h>
 #include <pro/sntp.h>
-#include "network.h"
+
 #include "ntp.h"
+#include "network.h"
 #include "jsmn.h"
 #include "rtc.h"
 #include "alarm.h"
 
 bool isReceiving;
+bool hasNetwork;
 u_short mss = 1460;
 u_long rx_to = 3000;
 u_short tcpbufsiz = 1500;
 
 void NetworkInit() {
+    hasNetwork = false;
     /* Register de internet controller. */
     if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
         printf("Registering  failed. \n");
@@ -41,6 +44,7 @@ void NetworkInit() {
     }else {
         printf("Ik heb een internet connectie. Ip is: %s \n\n", inet_ntoa(confnet.cdn_ip_addr));
     }
+    hasNetwork = true;
 }
 
 char* httpGet(char address[]){
@@ -156,4 +160,8 @@ void parseAlarmJson(char* content){
 
 bool NetworkIsReceiving(void){
     return isReceiving;
+}
+
+bool hasNetworkConnection(void){
+    return hasNetwork;
 }

+ 2 - 1
network.h

@@ -5,7 +5,8 @@
 #ifndef _Network_H
 #define _Network_H
 
-
+bool hasNetworkConnection(void);
+bool NetworkIsReceiving(void);
 extern void NetworkInit(void);
 char* httpGet(char address[]);
 void parseAlarmJson(char* content);