Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor I
1,321 Views

Setting Up Distribute and Flask Web Server on Galileo

Hi All

I haven't seen anyone use Flask on the Galileo, which is a shame as it is a great way to include a web interface in your projects

Distribute is a way of installing programs, and you may have used it on other platforms with the command "easy_install" and Flask is a really nice, easy to use, Web Server.

Below are my notes on how to set up a Galileo and used Flask. I assume you are familiar with how to work with Linux and are coming from a background with Arduino and/or Raspberry Pi.

If you already have AlexT's uClibc-based distribution of Yocto running and a text editor you like, you can skip to Install distribute and Flask below.

 

If confused as to what you are running, see /message/241845# 241845 https://communities.intel.com/message/241845# 241845 for a discussion of different versions.

First things is to get the Galileo up and running.

 

There are a number of good tutorials, such as one I like at SparkFun. https://learn.sparkfun.com/tutorials/galileo-getting-started-guide https://learn.sparkfun.com/tutorials/galileo-getting-started-guide

 

Do not forget to update the firmware or will have problems.

When you reach the part about installing the bigger form of Linux, download Alex's developmental version of Linux.

 

You can check /message/239581# 239581 https://communities.intel.com/message/239581# 239581 to find the latest version.

 

But for now it is at http://telekinect.media.mit.edu/galileo/image-devtools-1.0.1-3.tar.bz2 http://telekinect.media.mit.edu/galileo/image-devtools-1.0.1-3.tar.bz2

 

Uncompress and copy to a micro SD card. You can now insert the micro SD card and power up the Galileo.

Finding the IP address and hostname 

As discussed on Clay and Galileo (http://www.hofrock.com/connecting-to-linux http://www.hofrock.com/connecting-to-linux) there are a number of ways to connect to the Galileo.

Since the system at my university assigns new IP addresses every time one connects and the each SD card has a different name, I like to have a small screen display the hostname and IP address, as it makes connecting easier.

In addition, since the Galileo is so easily damaged if the USB cable is left in when power is lost, and a normal LCD shield or screen uses a lot of GPIO pins, I would suggest using an I2C LCD.

 

You can set up a I2C backpack LCD or Grove RGB LCD to show IP address following instructions at /thread/57741?sr=inbox https://communities.intel.com/thread/57741?sr=inbox

If you want to use an LCD screen, the following sketch will display the IP address onto an DFRobot LCD screen. Just be sure to remove the USB cable once the sketch is loaded so you don't forget and turn power off with it connected.

/*

 

LCD_Print_IP

 

Richard Bradley

 

Program to display IP Address on DFRobot LCD Shield

 

Note: Ethernet cable must be plugged in prior to starting Galileo or it won't get an address

 

Note: Need to put electrical tape on LCD or will short against Ethernet port connector

 

Note: Needs updated Liquid Crystal Library

 

https://github.com/mikalhart/galileo-LiquidCrystal/releases/ https://github.com/mikalhart/galileo-LiquidCrystal/releases/

 

Download and put in Sketches/library directory

 

Based on sketches from

 

http://www.arduino.cc/en/Tutorial/LiquidCrystal http://www.arduino.cc/en/Tutorial/LiquidCrystal

 

and http://www.cyberciti.biz/faq/how-to-find-out-the-ip-address-assigned-to-eth0-and-display-ip-only/ http://www.cyberciti.biz/faq/how-to-find-out-the-ip-address-assigned-to-eth0-and-display-ip-only/

 

and /thread/45335 https://communities.intel.com/thread/45335

 

---------------------------------------------------

 

The circuit:

 

* LCD RS pin to digital pin 12

 

* LCD Enable pin to digital pin 11

 

* LCD D4 pin to digital pin 5

 

* LCD D5 pin to digital pin 4

 

* LCD D6 pin to digital pin 3

 

* LCD D7 pin to digital pin 2

 

* LCD R/W pin to ground

 

* 10K resistor:

 

* ends to +5V and ground

 

* wiper to LCD VO pin (pin 3)

 

*/

// include the library code:

 

# include

 

// initialize the library with the numbers of the interface pins

 

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

 

char FileBuffer[15]; //set up space to read in files

void setup() {

 

// set up the LCD's number of columns and rows:

 

lcd.begin(16, 2);

 

// Print a message to the LCD.

 

lcd.setCursor(0, 0);

 

lcd.print("Welcome to VGU!");

 

// initialize serial communications:

 

//Serial.begin(9600);

 

// Start the telnet server on Galileo

 

system("telnetd -l /bin/sh");

 

delay(5000);

 

}

void loop()

 

{

 

// Call ifconfig, pipe through grep to get ipaddress and redirect to file in /home/root

 

system("ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'>/home/root/ip.txt");

 

FILE *fp;

 

fp=fopen("/home/root/ip.txt","r");

 

fgets(FileBuffer, 15, fp);

 

fclose(fp);

 

lcd.setCursor(0, 1);

 

lcd.print(FileBuffer);

 

delay(5000);

 

}

Set up access to Alex's repository</st...

0 Kudos
1 Reply
Highlighted
Valued Contributor I
10 Views

Hi All

Matt Richardson put up a great little tutorial on Flask for Raspberry Pi where he set up a web server that controlled pins via a web page

http://mattrichardson.com/Raspberry-Pi-Flask/ Serving Raspberry Pi with Flask - Matt Richardson, Creative Technologist

I ported the example to the Galileo using wiring_x86 (see /message/266970# 266970 https://communities.intel.com/message/266970# 266970 for how to set up wiring) and am controlling LEDs using pins 13 & 7 (BTW - make sure you use a resistor with pin 7 (I used 390R as didn't need it so bright) or you will burn out the LED quickly)

You can easily modify this to control multiple devices.

After you install wiring_x86 you can copy the attached files to /media/realroot and run weblamp.py

Since the webserver is using port 80, you just need to put in your IP address, or .local (if you have bonjour running) in the URL line of your browser

For an explanation of how it works, please go to Matt Richardson's website mentioned above.

Hope it is useful to someone.

Merry Christmas

RGB