Explorar el Código

Started developing twitch support (implemented methods for parsing data from json)

Aareschluchtje hace 9 años
padre
commit
14a88728d6
Se han modificado 3 ficheros con 42 adiciones y 1 borrados
  1. 37 0
      contentparser.c
  2. 1 0
      contentparser.h
  3. 4 1
      main.c

+ 37 - 0
contentparser.c

@@ -102,3 +102,40 @@ void parsetimezone(char* content)
     int timezone = atoi(content);
     printf("%d", timezone);
 }
+
+void parseTwitch(char* content)
+{
+    int r;
+    int i = 2;
+    jsmn_parser p;
+    jsmntok_t token[20]; /* We expect no more than 20 tokens */
+
+    jsmn_init(&p);
+    r = jsmn_parse(&p, content, strlen(content), token, sizeof(token)/sizeof(token[0]));
+    if (r <= 0) {
+        printf("Failed to parse JSON: %d \n", r);
+        return;
+    }else{
+        printf("Aantal tokens found: %d \n", r);
+    }
+
+    char name[20];
+    char title[30];
+    char game[20];
+
+    for(i; i < r; i+=2)
+    {
+        if(jsoneq(content, &token[i], "Name"))
+        {
+            getStringToken(content, &token[i+1], name);
+        }
+        else if(jsoneq(content, &token[i], "Title"))
+        {
+            getStringToken(content, &token[i+1], title);
+        }
+        else if(jsoneq(content, &token[i], "Game"))
+        {
+            getStringToken(content, &token[i+1], game);
+        }
+    }
+}

+ 1 - 0
contentparser.h

@@ -6,5 +6,6 @@
 
 void parseAlarmJson(char* content);
 void parsetimezone(char* content);
+void parseTwitch(char* content);
 
 #endif //CONTENTPARSER_H

+ 4 - 1
main.c

@@ -227,9 +227,12 @@ THREAD(AlarmSync, arg)
         if(initialized && (hasNetworkConnection() == true))
         {
             isAlarmSyncing = 1;
-            char url[43];
+            char url[43];           //cause of memory leak maybe?
             sprintf(url, "%s%s", "/getAlarmen.php?radiomac=", getMacAdress());
             httpGet(url, parseAlarmJson);
+            char url2[43];
+            sprintf(url2, "/getTwitch.php?radiomac=%s", getMacAdress());
+            httpGet(url2, parseTwitch);
             isAlarmSyncing = 0;
         }
         NutSleep(3000);