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

Simplify configuring which device to get IP address from. #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ sudo reboot
```
**Wait for the system to restart**

## Clone SKU_RM0004 library
## Clone SKU_RM0004 library
```bash
git clone https://github.com/UCTRONICS/SKU_RM0004.git
```
## Compile
## Configure
Modify `rpiInfo.h` and set `IPADDRESS_INTERFACE` to the interface to use to display the IP address from.

## Compile
```bash
cd SKU_RM0004
make
```
## Run
## Run
```
./display
```
Expand All @@ -44,14 +47,8 @@ sudo nano /etc/rc.local
**Add command to the rc.local file**
```bash
cd /home/pi/SKU_RM0004
make clean
make
make clean
make
./display &
```
**reboot your system**






85 changes: 28 additions & 57 deletions hardware/rpiInfo/rpiInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,28 @@
#include <stdlib.h>

/*
* Get the IP address of wlan0 or eth0
*/
* Get the IP address of the interface defined in IPADDRESS_INTERFACE
*/

char* get_ip_address(void)
{
int fd;
struct ifreq ifr;
int symbol=0;
if (IPADDRESS_TYPE == ETH0_ADDRESS)
{
fd = socket(AF_INET, SOCK_DGRAM, 0);
/* I want to get an IPv4 IP address */
ifr.ifr_addr.sa_family = AF_INET;
/* I want IP address attached to "eth0" */
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);
symbol=ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
if(symbol==0)
{
return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
}
else
{
char* buffer="xxx.xxx.xxx.xxx";
return buffer;
}
}
else if (IPADDRESS_TYPE == WLAN0_ADDRESS)
{
fd = socket(AF_INET, SOCK_DGRAM, 0);
/* I want to get an IPv4 IP address */
ifr.ifr_addr.sa_family = AF_INET;
/* I want IP address attached to "wlan0" */
strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ-1);
symbol=ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
if(symbol==0)
{
return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
}
else
{
char* buffer="xxx.xxx.xxx.xxx";
return buffer;
}
}
else
{
char* buffer="xxx.xxx.xxx.xxx";
return buffer;
}
int fd;
struct ifreq ifr;
int symbol = 0;
char *buffer = "xxx.xxx.xxx.xxx";
fd = socket(AF_INET, SOCK_DGRAM, 0);
/* I want to get an IPv4 IP address */
ifr.ifr_addr.sa_family = AF_INET;
/* I want IP address attached to "wlan0" */
strncpy(ifr.ifr_name, IPADDRESS_INTERFACE, IFNAMSIZ - 1);
symbol = ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
if (symbol == 0)
{
buffer = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
}

return buffer;
}

/*
Expand Down Expand Up @@ -103,8 +74,8 @@ void get_cpu_memory(float *Totalram,float *freeram)
*freeram=value/1000.0/1000.0;
}
}
fclose(fp);
}
fclose(fp);
}
}

/*
Expand All @@ -115,7 +86,7 @@ void get_sd_memory(uint32_t *MemSize, uint32_t *freesize)
struct statfs diskInfo;
statfs("/",&diskInfo);
unsigned long long blocksize = diskInfo.f_bsize;// The number of bytes per block
unsigned long long totalsize = blocksize*diskInfo.f_blocks;//Total number of bytes
unsigned long long totalsize = blocksize*diskInfo.f_blocks;//Total number of bytes
*MemSize=(unsigned int)(totalsize>>30);


Expand All @@ -135,11 +106,11 @@ uint8_t get_hard_disk_memory(uint16_t *diskMemSize, uint16_t *useMemSize)
uint8_t diskMembuff[10] = {0};
uint8_t useMembuff[10] = {0};
FILE *fd = NULL;
fd=popen("df -l | grep /dev/sda | awk '{printf \"%s\", $(2)}'","r");
fd=popen("df -l | grep /dev/sda | awk '{printf \"%s\", $(2)}'","r");
fgets(diskMembuff,sizeof(diskMembuff),fd);
fclose(fd);

fd=popen("df -l | grep /dev/sda | awk '{printf \"%s\", $(3)}'","r");
fd=popen("df -l | grep /dev/sda | awk '{printf \"%s\", $(3)}'","r");
fgets(useMembuff,sizeof(useMembuff),fd);
fclose(fd);

Expand All @@ -160,7 +131,7 @@ uint8_t get_temperature(void)
fgets(buff,sizeof(buff),fd);
sscanf(buff, "%d", &temp);
fclose(fd);
return TEMPERATURE_TYPE == FAHRENHEIT ? temp/1000*1.8+32 : temp/1000;
return TEMPERATURE_TYPE == FAHRENHEIT ? temp/1000*1.8+32 : temp/1000;
}

/*
Expand All @@ -176,13 +147,13 @@ uint8_t get_cpu_message(void)

fp=popen("top -bn1 | grep %Cpu | awk '{printf \"%.2f\", $(2)}'","r"); //Gets the load on the CPU
fgets(usCpuBuff, sizeof(usCpuBuff),fp); //Read the user CPU load
pclose(fp);
pclose(fp);

fp=popen("top -bn1 | grep %Cpu | awk '{printf \"%.2f\", $(4)}'","r"); //Gets the load on the CPU
fgets(syCpubuff, sizeof(syCpubuff),fp); //Read the system CPU load
pclose(fp);
pclose(fp);
usCpu = atoi(usCpuBuff);
syCpu = atoi(syCpubuff);
return usCpu+syCpu;

}
4 changes: 1 addition & 3 deletions hardware/rpiInfo/rpiInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
/**********Select display temperature type**************/

/**********Select display network IP type**************/
#define ETH0_ADDRESS 0
#define WLAN0_ADDRESS 1
#define IPADDRESS_TYPE ETH0_ADDRESS // or WLAN0_ADDRESS for WiFi
#define IPADDRESS_INTERFACE "eth0" // or WLAN0_ADDRESS for WiFi
/**********Select display network IP type**************/


Expand Down