From 41774c2110386c27eb7d3d1ad0917c6135a5b0c7 Mon Sep 17 00:00:00 2001 From: sherrychen127 Date: Fri, 28 Jun 2019 23:29:10 -0400 Subject: [PATCH] added ip address retrieval --- .DS_Store | Bin 8196 -> 8196 bytes Development/.DS_Store | Bin 8196 -> 8196 bytes Development/Jetson_I2C_GLCD/ip_address.py | 18 ++++++++++++ .../Jetson_I2C_GLCD/jetson_i2c_glcd.cpp | 27 ++++++++++++++++-- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 Development/Jetson_I2C_GLCD/ip_address.py diff --git a/.DS_Store b/.DS_Store index 867620604b22df0818eb09d6265dfa1b9ccdf754..d311e28c110f5240a244c050f96e784cb601a22b 100644 GIT binary patch delta 41 xcmZp1XmQwZQgE`bNDGsp!DK%n<;mYfR3;Y+if>*c6veukUE&+d=076r%m6rW4q5;J delta 40 wcmZp1XmQwZQgCvoKntVAWPc&$$%cX|lM4mKH?I|nV%^Lp@ttM!KM{6j03{v`qyPW_ diff --git a/Development/.DS_Store b/Development/.DS_Store index b3e70dee61c55700911f520ae898bf715e377b56..f303cc227146061a2c9e0422cae3465af0419d23 100644 GIT binary patch delta 60 zcmV-C0K@-;K!iZB-w^@Ili(463mJQRGBPqOAT2pDlW7tj0h*J66(0eclW-Fvv&s@X S1+xbj_5_pO6JE1f6{!M&F%-7| delta 45 zcmZp1XmQwZUvTm*krp-!OC1F>^U2vla+8}xRVF(N%Wpm-WX-ynRpJNB=Kmt>%m8u^ B4^IF9 diff --git a/Development/Jetson_I2C_GLCD/ip_address.py b/Development/Jetson_I2C_GLCD/ip_address.py new file mode 100644 index 00000000..e6e24cff --- /dev/null +++ b/Development/Jetson_I2C_GLCD/ip_address.py @@ -0,0 +1,18 @@ +import socket +import os +f = os.popen('ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1') +IPAddr=f.read() + + +#hostname = socket.gethostname() +#IPAddr = socket.gethostbyname(hostname) + +#print("Your Computer Name is:" + hostname) +#print("Your Computer IP Address is:" + IPAddr) +def main(): + file = open(r"ip.txt", "w+") + file.write(IPAddr) + file.close() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/Development/Jetson_I2C_GLCD/jetson_i2c_glcd.cpp b/Development/Jetson_I2C_GLCD/jetson_i2c_glcd.cpp index 50705fe6..6189fd58 100755 --- a/Development/Jetson_I2C_GLCD/jetson_i2c_glcd.cpp +++ b/Development/Jetson_I2C_GLCD/jetson_i2c_glcd.cpp @@ -17,6 +17,10 @@ #include #include +//#include +#include +using namespace std; + #include #define BLACK 0 @@ -431,7 +435,7 @@ int cursor_x = 0; int textsize = 0; uint16_t textcolor = 0xFFFF; uint16_t textbgcolor = 0xFFFF; -char ip[14] = "138.51.120.89"; +//char ip[14] = "138.51.120.89"; void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size); @@ -763,6 +767,25 @@ void print_ip_address(char ip_address[]){ int main(){ + int result = system("python ip_address.py 1"); + int arraysize=14; + char ip[arraysize]; + char current_char; + + int num_characters = 0; + int i = 0; + + ifstream myfile; + myfile.open("ip.txt"); + if (myfile.is_open()){ + while(!myfile.eof()){ + myfile >> ip; + + } + } + printf("%s",ip); + myfile.close(); + int FileDescriptor = open(); begin(FileDescriptor); @@ -776,4 +799,4 @@ int main(){ close(FileDescriptor); return 0; -} +} \ No newline at end of file