Browse Source

piumsgd now serves local html

* cleaning up where things are located
* still testing
clementinecomputing 5 years ago
parent
commit
7e771d7ded

+ 1 - 1
busunit-PIU/html/index.html

@@ -87,7 +87,7 @@
         </div>
 
         <div class='pure-u-5-6 col'>
-          <div class='bdisp' style='color:#999a99;' id='ui_message_status' >SEE DRIVER</div> <br>
+          <div class='bdisp' style='color:#999a99;' id='ui_message_status' >SEE DRIVER...</div> <br>
           <img id='ui_main_vidfeed' style='height:50vh;' src='' ></img> <br>
           <div class='bdisp' id='ui_message_cardinfo'>...</div>
         </div>

+ 2 - 2
busunit-PIU/html/js/piu_ui.js

@@ -19,7 +19,7 @@
  */
 
 //var _ADDRESS = "localhost";
-var _ADDRESS = "192.168.0.26";
+var _ADDRESS = "127.0.0.1";
 var _URL = "http://" + _ADDRESS;
 var _PORT = 60535;
 var _WS_PORT = 8001;
@@ -35,7 +35,7 @@ var _fqADDRESS = _ADDRESS + ":" + _PORT;
 // Use 127.0.0.1 instead
 //
 //var _wsADDRESS = "localhost" + ":" + _WS_PORT;
-var _wsADDRESS = "127.0.0.1" + ":" + _WS_PORT;
+var _wsADDRESS = "127.0.0.1" + ":" + _WS_PORT + "/ws";
 
 var BG_COLOR = "#f7f7f7";
 var TEXT_COLOR = "#444444";

+ 13 - 2
busunit-PIU/piumsgd/client/piumsg.c

@@ -37,7 +37,8 @@
 #define PIUMSG "piumsg"
 
 #define PIUMSG_VERSION "0.1.0"
-#define PIUMSG_HOST "localhost"
+#define PIUMSG_HOST "127.0.0.1"
+#define PIUMSG_PATH "ws"
 
 //#define PIUMSG_HOST "ws://192.168.0.26"
 #define PIUMSG_PORT 8001
@@ -45,6 +46,7 @@
 #define _BUFLEN 1024
 
 char *g_host = NULL;
+char *g_path= NULL;
 int g_port = PIUMSG_PORT;
 char *g_msg = NULL;
 
@@ -120,6 +122,7 @@ void show_help(FILE *fp) {
   fprintf(fp, "\n");
   fprintf(fp, "  msg        push message\n");
   fprintf(fp, "  [-H host]  host (default %s)\n", PIUMSG_HOST);
+  fprintf(fp, "  [-P path]  path on host (default %s)\n", PIUMSG_PATH);
   fprintf(fp, "  [-p port]  port (default %i)\n", PIUMSG_PORT);
   fprintf(fp, "  [-V]       verbose\n");
   fprintf(fp, "  [-h]       help (this screen)\n");
@@ -143,6 +146,9 @@ int main(int argc, char **argv) {
       case 'H':
         g_host = strdup(optarg);
         break;
+      case 'P':
+        g_path = strdup(optarg);
+        break;
       case 'p':
         g_port = atoi(optarg);
         break;
@@ -174,7 +180,11 @@ int main(int argc, char **argv) {
     g_host = strdup(PIUMSG_HOST);
   }
 
-  snprintf(s_url, _BUFLEN-1, "ws://%s:%i", g_host, g_port);
+  if (!g_path) {
+    g_path = strdup(PIUMSG_PATH);
+  }
+
+  snprintf(s_url, _BUFLEN-1, "ws://%s:%i/%s", g_host, g_port, g_path);
   s_url[_BUFLEN-1]=0;
 
   mg_mgr_init(&mgr);
@@ -187,5 +197,6 @@ int main(int argc, char **argv) {
   mg_mgr_free(&mgr);
   free(g_msg);
   free(g_host);
+  free(g_path);
   return 0;
 }

+ 5 - 30
busunit-PIU/piumsgd/piumsgd.c

@@ -86,7 +86,7 @@ static void _cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
     printf("bang\n"); fflush(stdout);
 
     struct mg_http_message *hm = (struct mg_http_message *) ev_data;
-    if (mg_http_match_uri(hm, "/websocket")) {
+    if (mg_http_match_uri(hm, "/ws")) {
 
       // Upgrade to websocket. From now on, a connection is a full-duplex
       // Websocket connection, which will receive MG_EV_WS_MSG events.
@@ -97,8 +97,9 @@ static void _cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
     }
     else if (mg_http_match_uri(hm, "/")) {
 
-      printf("ws request? (1)\n"); fflush(stdout);
-      mg_ws_upgrade(c, hm, NULL);
+      printf("html request? (1)\n"); fflush(stdout);
+      struct mg_http_serve_opts opts = {.root_dir = s_web_directory};
+      mg_http_serve_dir(c, hm, &opts);
     }
     else if (mg_http_match_uri(hm, "/rest")) {
 
@@ -168,31 +169,5 @@ int main(int argc, char **argv) {
   }
   mg_mgr_free(&g_mgr);
 
-  exit(0);
-  /*
-
-  //loop until we get asked to exit.../
-  //
-  while (1) {
-
-
-    // Add our websocket socket to the list of file descriptors
-    // to select on.
-    //
-    for (nc = g_mgr.active_connections; nc != NULL; nc = nc->next) {
-
-      if (nc->sock != INVALID_SOCKET) {
-        if (nfd < 32) {
-          fds[nfd].fd = nc->sock;
-          fds[nfd].events = POLLIN | POLLOUT;
-          fds[nfd].revents = 0;
-          nfd++;
-        }
-      }
-    }
-
-
-  }
-  */
-
+  return 0;
 }