Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

added IP address retrieval #205

Open
wants to merge 1 commit into
base: master
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
Binary file modified .DS_Store
Binary file not shown.
Binary file modified Development/.DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions Development/Jetson_I2C_GLCD/ip_address.py
Original file line number Diff line number Diff line change
@@ -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()
27 changes: 25 additions & 2 deletions Development/Jetson_I2C_GLCD/jetson_i2c_glcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <iostream>
#include <fstream>

//#include <cstdlib>
#include <string>
using namespace std;

#include <math.h>

#define BLACK 0
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -763,6 +767,25 @@ void print_ip_address(char ip_address[]){


int main(){
int result = system("python ip_address.py 1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the 1 need to be passed in here?

int arraysize=14;
char ip[arraysize];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 14 always going to be large enough for the IP address? Maybe std::string could work better here

char current_char;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using all these local variables? If not, you can remove them


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);

Expand All @@ -776,4 +799,4 @@ int main(){
close(FileDescriptor);

return 0;
}
}