- int temperature;
- FILE *fp;
-
- /* open temperature file */
- if (!(fp = fopen(tempfile, "r"))) {
- fprintf(stderr, "Could not open temperature file.\n");
- exit(1);
- }
-
- /* extract temperature */
- fscanf(fp, "%d", &temperature);
-
- /* close temperature file */
- fclose(fp);
-
- /* return temperature in degrees */
- return smprintf("%d°C", temperature / 1000);
-}
-
-/* wifi percentage */
-char *
-wifi_signal()
-{
- int bufsize = 255;
- int strength;
- char buf[bufsize];
- char *datastart;
- char path_start[16] = "/sys/class/net/";
- char path_end[11] = "/operstate";
- char path[32];
- char status[5];
- FILE *fp;
-
- /* generate the path name */
- strcat(path, path_start);
- strcat(path, wificard);
- strcat(path, path_end);
-
- /* open wifi file */
- if(!(fp = fopen(path, "r"))) {
- fprintf(stderr, "Error opening wifi operstate file.");
- exit(1);
- }
-
- /* read the status */
- fgets(status, 5, fp);
-
- /* close wifi file */
- fclose(fp);
-
- /* check if interface down */
- if(strcmp(status, "up\n") != 0){
- return "n/a";
- }
-
- /* open wifi file */
- if (!(fp = fopen("/proc/net/wireless", "r"))) {
- fprintf(stderr, "Error opening wireless file.");
- exit(1);
- }
-
- /* extract the signal strength */
- fgets(buf, bufsize, fp);
- fgets(buf, bufsize, fp);
- fgets(buf, bufsize, fp);
- if ((datastart = strstr(buf, "wlp3s0:")) != NULL) {
- datastart = strstr(buf, ":");
- sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d",
- &strength);
- }
-
- /* close wifi file */
- fclose(fp);
-
- /* return strength in percent */
- return smprintf("%d%%", strength);