Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending telemetric data to DCM #14

Open
VampireSilence opened this issue Apr 8, 2023 · 1 comment
Open

Sending telemetric data to DCM #14

VampireSilence opened this issue Apr 8, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@VampireSilence
Copy link

VampireSilence commented Apr 8, 2023

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;
}
@clburlison
Copy link
Owner

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

@clburlison clburlison added the enhancement New feature or request label Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants