Hi! i'm trying to send data via post to a website from Arduino YUN and insert them into a database, i'm trying to send a not-dynamic query string as test, but it doesn't work..
I assume you intend for the function runCurl() to upload a sample to your PHP page. But while you define that function, you don't actually call it anywhere.
Your loop() function does nothing but create an instance of BridgeClient, and then it exits, throwing away the BridgeClient object. Of course, it does this over and over again. What is BridgeClient, BridgeClient.h, and BridgeServer.h? Where did you get them and what are you trying to accomplish with them? You also define an IPAddress object that is never used.
And just to be sure, you do realize that this statement means the sketch will stop and wait there until you open a connection through the micro-USB serial connection, right?
while(!Serial);
Normally this is added to the beginning of a sketch so that all of the serial output can be seen on the serial monitor, but I question it because you don't actually print out any serial output.
I understand enough PHP but I'm new with Arduino. I tried to take inspiration from other sketckes but i didn't succeed with anyone of them, that's why my sketch was a little "confused"..
I tried in this way:
// include il bridge
#include <Bridge.h>
void setup() {
// Initialize Bridge
Bridge.begin();
}
// eseguo il loop che esegue runCurl
void loop()
{
// inizializzo la funzione runCurl
runCurl();
delay(5000);
}
// dichiaro la funzione runCurl
void runCurl()
{
Process p;
String cmd = "curl --data-urlencode \"amount=300&moment=2015-11-28 23:59:00\"www.mysite.com/addVal.php?";
p.runShellCommand(cmd);
p.close();
}
Thanks even for the suggestion about the TIMESTAMP, i didn't know about it.. anyway, I didn't use dynamic values for time in order to make the Arduino sketch simpler.
Hi, I think I guessed the code.
At the moment it works ...
What do you think about it?
//includo le librerie Bridge e Process
#include <Bridge.h>
#include <Process.h>
void setup() {
// Initializzo Bridge
Bridge.begin();
// Initializzo Serial
Serial.begin(9600);
// Wait until a Serial Monitor is connected.
while (!Serial);
Serial.println("Ready");
runCurl();
delay(100000);
}
void loop() {
}
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
String myUrl = "http://mysite.com/addVal.php?amount=300&moment=2015-11-29+23%3A23%3A23";
p.addParameter(myUrl); // Add the URL parameter to "curl"
p.run(); // Run the process and wait for its termination
// 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();
}