How to make a curl request on Arduino Mega? Getting gibberish (“úøøýþý…”)

Hi,

I am running into issues make a curl request on an Arduino Mega. I found a tutorial about how to do it on an Arduino Yun, but it doesn’t seem to be working on the Mega. I’m sorry if this is a dumb question but I would really appreciate any help you can offer! I have been trying to figure this out for hours.

Here is the full code I am uploading:

#include <Bridge.h>
#include <BridgeClient.h>
#include <BridgeServer.h>
#include <BridgeSSLClient.h>
#include <BridgeUdp.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Mailbox.h>
#include <Process.h>
#include <BridgeClient.h>
#include <BridgeServer.h>

/*
Running process using Process class.

This sketch demonstrate how to run linux processes
using an Arduino Yún.

created 5 Jun 2013
by Cristian Maglie

This example code is in the public domain.

*/

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

}

void loop() {
Serial.print(“Looping!”);
}

void runCurl() {
// 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(“curl”); // Process that launch the “curl” command
p.addParameter(“http://www.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();
}

But instead of printing the characters in https://www.arduino.cc/asciilogo.txt it is just printing a bunch of gibberish characters. Everything is in 9600 BAUD. Help?

but it doesn't seem to be working on the Mega

Of course not. The Yun has an Arduino side and a linux side. The bridge software allows them to talk. The Mega has no linux side, so the bridge software is a bridge to nowhere. Get a Yun.

Thank you for replying! Is it possible for the Mega to make curl requests some other way? I realize I bought the wrong board, but I'd like to see what I can do with it. Is it impossible?

Is it possible for the Mega to make curl requests some other way?

Yes. The Mega could send the request to a Yun.

Thank you for your help, PaulS. https://www.arduino.cc/en/Guide/ArduinoYun says the Yun is retired but I will look into it. It's pretty disappointing to me that I'll have to get a new Arduino to do this. Oh well.

You could also use a Raspberry Pi, libraries exists for bridging between an arduino and a RBPi. A RBPi will be much faster and more versatile than a Yun. It would not surprise me if a RBPi is cheaper than a Yun :slight_smile:

p.begin("curl"); // Process that launch the "curl" command
p.addParameter("http://www.arduino.cc/asciilogo.txt");

"Curl" is a linux program for retrieving assorted internet content over a network connection.
Arduino Mega (MOST arduinos) don't have this.
I'm sure that "curl" is wonderfully powerful. There are other ways to retrieve this info.

  • If you just want that particular text logo, access it with your favorite web browser and copy/paste into your sketch.
  • If it will consistently be an http site you're accessing, and your MEGA has a network connection of some kind, you can use something like the "HTTPClient" example. Note that the MEGA doesn't have enough memory to sit around with massive web pages sitting in its memory waiting to be accessed, so the details might be a bit different.
  • Move all the web content you are likely to use to an SD card or flash memory, and access it with the arduino file-system libraries.