clburlison/dmon

Sending telemetric data to DCM

VampireSilence opened this issue · 1 comments

Sending telemetric data to DCM (or any other backend) could provide better traceability of random device reboots etc.
If desired, i can make a backend that can retrieve that data and generate graphs for each device and parameter.

int sendTelemetricData (void)
{
    // Device name
    NSString *deviceName = [[UIDevice currentDevice] name];
	
    // Battery percentage
    UIDevice *device = [UIDevice currentDevice];
    device.batteryMonitoringEnabled = YES;
    float batteryLevel = [device batteryLevel] * 100.0f;
    
    // CPU temperature
    int mib[2];
    mib[0] = CTL_HW;
    mib[1] = HW_CPU_TEMPERATURE;
    int64_t temperature;
    size_t length = sizeof(temperature);
    sysctl(mib, 2, &temperature, &length, NULL, 0);
    float cpuTemp = temperature / 100.0f;
    
    // Init
    CURL *curl;
    CURLcode res;
    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();
    
    if (curl)
	{
        curl_easy_setopt(curl, CURLOPT_URL, "http://YOUR_DCM_URL");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "device_name=%f&battery_percentage=%f&cpu_temperature=%f", [deviceName UTF8String], batteryLevel, cpuTemp);
        
        res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            fprintf(stderr, "dmon: curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        }
        
        curl_easy_cleanup(curl);
    }
    
    curl_global_cleanup();
    return 0;
}

Sounds good to me. Not something I'll be looking at this week as I'm busy.