Browse Source

implement /device for device detection purposes

Helmut Pozimski 5 years ago
parent
commit
8f074d95ac
3 changed files with 17 additions and 0 deletions
  1. 1 0
      README.md
  2. 1 0
      jsonrtc/conf/jsonrtc.conf
  3. 15 0
      jsonrtc/src/jsonrtc.c

+ 1 - 0
README.md

@@ -10,6 +10,7 @@ Execute `kodev run` to start the web service. You can then issue requests to the
 
 * /time (either GET or POST)
 * /wkalrm (either GET or POST)
+* /device (GET only)
 
 ## Parameters
 

+ 1 - 0
jsonrtc/conf/jsonrtc.conf

@@ -12,4 +12,5 @@ domain * {
 	static	/	page
 	static	/time	handle_time
 	static /wkalrm	handle_wkalrm
+	static /device  detect_device
 }

+ 15 - 0
jsonrtc/src/jsonrtc.c

@@ -30,6 +30,7 @@
 int		page(struct http_request *);
 int handle_time(struct http_request *);
 int handle_wkalrm(struct http_request *);
+int detect_device(struct http_request *);
 
 int
 page(struct http_request *req)
@@ -248,3 +249,17 @@ int handle_wkalrm(struct http_request *req) {
                 return (KORE_RESULT_OK);
 	}
 }
+
+int detect_device(struct http_request *req) {
+	if(req->method == HTTP_METHOD_GET) {
+		if (access("/sys/bus/nvmem/devices/ds1307_nvram0/nvmem", F_OK) != -1) {
+			http_response(req, 200, "DS1307", 6);
+		} else {
+			http_response(req, 200, "DS1337", 6);
+		}
+		return KORE_RESULT_OK;
+	} else {
+		http_response(req, HTTP_STATUS_METHOD_NOT_ALLOWED, NULL, 0);
+                return (KORE_RESULT_OK);
+	}
+}