Yun python https project

Hey,

I want to run a python script via the onboard memory of the Yun that makes requests to an https api and then prints to my serial.
Is this even possible to do? I can't find any https documention for python 2.7 online.

Also, is it possible for the yun to do https requests via the "wget" command? If so, could you provide me with sample code.
I tried the code below but it wasn't working.
Here's my adaptation of code from an example on the Yun Bridge Reference. I'm very new to linux and terminal commands.


#include <FileIO.h>

void setup() {
// Setup Bridge (needed every time we communicate with the Arduino Yún)
Bridge.begin();
// Initialize the Serial
Serial.begin(9600);

while(!Serial); // wait for Serial port to connect.
Serial.println("File Write Script example\n\n");

// Setup File IO
FileSystem.begin();

// Upload script used to gain network statistics
uploadScript();
}

void loop()
{
// Run stats script every 5 secs.
runScript();
delay(5000);
}

void uploadScript()
{
File script = FileSystem.open("/tmp/example.sh", FILE_WRITE);
// Shell script header
script.print("#!/bin/sh\n");
script.print("wget -o https://example.com");
script.close(); // close the file

// Make the script executable
Process chmod;
chmod.begin("chmod"); // chmod: change mode
chmod.addParameter("+x"); // x stays for executable
chmod.addParameter("/tmp/example.sh"); // path to the file to make it executable
chmod.run();
}

// this function run the script and read the output data
void runScript()
{
// Run the script and show results on the Serial
Process myscript;
myscript.begin("/tmp/example.sh");
myscript.run();

String output = "";

// read the output of the script
while (myscript.available())
{
output += (char)myscript.read();
}
// remove the blank spaces at the beginning and the ending of the string
output.trim();
Serial.println(output);
Serial.flush();
}


Thanks for the help!!

opkg update 
opkg install python-openssl
opkg install  nano
nano /mnt/sda1/httpsget.py
#!/usr/bin/python
import httplib
conn = httplib.HTTPSConnection("www.google.com")
conn.request("GET", "/")
r = conn.getresponse()
print r.read()
chmod 755  /mnt/sda1/httpsget.py
/mnt/sda1/httpsget.py
#include <Process.h>

void setup() {
  // Initialize Bridge
  Bridge.begin();

  // Initialize Serial
  Serial.begin(9600);

  // Wait until a Serial Monitor is connected.
  while (!Serial);

  // run various example processes
  //runCurl();
  //runCpuInfo();
  httpsget();
}

void loop() {
  // Do nothing here.
}

void httpsget() {
  // Launch "curl" command and get Arduino ascii art logo from the network
  // curl is command line program for transferring data using different internet protocols
  Process p;		// Create a process and call it "p"
  p.begin("/mnt/sda1/httpsget.py");	// Process that launch the "curl" command
  //p.addParameter("http://arduino.cc/asciilogo.txt"); // Add the URL parameter to "curl"
  p.run();		// Run the process and wait for its termination

  // Print arduino logo over the Serial
  // A process output can be read with the stream methods
  while (p.available() > 0) {
    char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();
}

How do you enter the first series of commands(eg. opkg update, opkg install python-openssl)?

I entered them into my computer terminal but nothing happens.

mjmostachetti:
How do you enter the first series of commands(eg. opkg update, opkg install python-openssl)?

I entered them into my computer terminal but nothing happens.

They need to be entered/run on the shell of the Yun of course!

Ralf

Is there any other way to write to linino other than writing through a sketch?

I guess my question is more, do you need to write that code into the Linux terminal or can you write it into a process and run it that way. What's the difference between Linux shell and terminal? I thought they were synonymous.

mjmostachetti:
Is there any other way to write to linino other than writing through a sketch?

Come again? :expressionless:
Any sketch runs on the Atmel (Leonardo) side of the Yun, Linino runs on the MIPS side of it. The way to communicate between those two is through the bridge...

Ralf

I'm wondering if I could rebuild the arduino linino source code with some scripts on it, rather than adding them within my arduino sketch.

Right now - possibly due to my lack of arduino knowledge - I only know of adding scripts to the MIPS side via the FileSystem library. Are there other ways of doing this?

Also, when I run:

void opkg()
{
  Process update;
  update.begin("opkg");
  update.addParameter("update");
  update.run();
  Serial.println("opkg");
  Process update1;
  update1.begin("opkg");
  update1.addParameter("install");
  update1.addParameter("update-openssl");
  update1.run();
  Serial.println("install openssl");
  Process update2;
  update2.begin("opkg");
  update2.addParameter("install");
  update2.addParameter("nano");
  update2.run();
  Serial.println("install nano");
}

is this the right code for invoking the opkg?

:astonished: :astonished: :astonished:
Sorry, but I almost spilled my coffee... :fearful:

You can access the shell (command line interface) of the Yun at any time via it's IP address (or it's host name) using ssh (using PuTTY, to be found at Download PuTTY: latest release (0.78), in case you are using a Windows host) directly.

Why on earth would someone create a sketch on the AVR side just to push a (one time!) script up to the Linino side?

Talking about "Von hinten durch die Brust ins Auge...." (sorry, but a very matching German proverb for what you are trying to do).

Ralf