86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include "cJSON.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
char *buffer_json;
|
|
|
|
int read_file(const char *name)
|
|
{
|
|
FILE *fp;
|
|
|
|
fp = fopen(name, "r");
|
|
fseek(fp, 0, SEEK_END);
|
|
long size = ftell(fp);
|
|
fseek(fp, 0, SEEK_SET);
|
|
buffer_json = malloc(size);
|
|
fread(buffer_json, size, 1, fp);
|
|
|
|
|
|
fclose(fp);
|
|
}
|
|
|
|
|
|
#if 0
|
|
cJSON *json_mesh_ip = cJSON_GetObjectItem(json, "mesh_IP");
|
|
|
|
if(json_mesh_ip){
|
|
|
|
cJSON *count = cJSON_GetObjectItem(json_mesh_ip, "vsrc_count");
|
|
|
|
if( index > count->valueint){
|
|
printf("error index > ip_count \n");
|
|
return 0;
|
|
}else{
|
|
|
|
int n = sprintf(VSRC,"VSRC%d",index);
|
|
printf("mesh IP%d, %s\n",n,cJSON_GetArrayItem(cJSON_GetObjectItem(json_mesh_ip, VSRC),0)->valuestring);
|
|
|
|
strcpy(vsrcip1, cJSON_GetArrayItem(cJSON_GetObjectItem(json_mesh_ip, VSRC),0)->valuestring);
|
|
strcpy(vsrcip2, cJSON_GetArrayItem(cJSON_GetObjectItem(json_mesh_ip, VSRC),1)->valuestring);
|
|
}
|
|
|
|
#endif
|
|
|
|
int main(int argc , char **argv){
|
|
|
|
unsigned char wget[50];
|
|
|
|
snprintf(wget,50,"wget http://%s/status",argv[1]);
|
|
|
|
|
|
while(1){
|
|
|
|
system(wget);
|
|
|
|
read_file("./status");
|
|
|
|
cJSON *json =cJSON_Parse(buffer_json);
|
|
|
|
printf(cJSON_Print(json));
|
|
|
|
cJSON *json_node = cJSON_GetObjectItem(json, "nodesRssi");
|
|
cJSON *json_link = cJSON_GetObjectItem(json, "linkQuality");
|
|
|
|
|
|
if(json_node && json_link){
|
|
printf("rssi1 %f\n", cJSON_GetObjectItem(cJSON_GetArrayItem(json_node,0),"ant2Rssi")->valuedouble );
|
|
printf("rssi2 %f\n", cJSON_GetObjectItem(cJSON_GetArrayItem(json_node,0),"ant1Rssi")->valuedouble );
|
|
|
|
printf("snr %d \n ", cJSON_GetArrayItem(cJSON_GetArrayItem(json_link,1),0)->valueint);
|
|
|
|
}
|
|
|
|
|
|
free(buffer_json);
|
|
|
|
system("rm -rf status");
|
|
|
|
usleep(1000000);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|