I am using arduino leonardo with wifi shield.My problem is when i post data to server ;
#include <SPI.h>
#include <WiFi.h>
#include <TextFinder.h>
char ssid[] = "taylan";
char pass[] = "******";
int status = WL_IDLE_STATUS;
char server[] = "arduinocontrol.somee.com";
WiFiClient client;
TextFinder finder(client);
void setup(){
Serial.begin(9600);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid,pass);
// wait 10 seconds for connection:
delay(10000);
}
httpsendRequest();
}
void loop(){
while(client.available()) {
char c = client.read();
Serial.write(c);
}
}
void httpsendRequest(){
client.stop();
Serial.print(F("Connecting.."));
if (client.connect(server, 80)) {
String data="F=1&D0=230&D1=34&D2=34&D3=35&D4=35&D5=35&D6=35&D7=24&D8=37&D9=38&D10=10";//can send long data
client.println("POST /Graph.aspx HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
//client.println(data);
int x = data.length(), i=0,j;
const char * charptr=data.c_str(); // get access to the internal c_str of data.
while (i<x){
j=50;
if((i+j)>x) j = x - i;
client.write(&charptr[i],j); // starting at charptr[i] send then next j bytes.
i = i + j;
}
Serial.print(F("Send"));
}
else{
Serial.print(F("error"));
}
if my data is "Finish=1&Data0=22&Data1=24&Data2=66&Data3=39&Data4=38&Data5=26&Data6=11&Data7=3&Data8=100" which has smaller length it post the data and also i can see the page on serial .But above code never do post and can't see any html page on serial.
On server side i have code that takes post back data and write them to text.
Since i can't see any error i don't know why this is happening.I only assume its about content length but i want to send long string data.How can i do that? i have 180 data to send.
taylankaan:
I am using arduino leonardo with wifi shield.My problem is when i post data to server ;
Since i can't see any error i don't know why this is happening.I only assume its about content length but i want to send long string data.How can i do that? i have 180 data to send.
Try breaking the data into smaller block.
int x = data.length(), i=0,j;
const char * charptr=data.c_str(); // get access to the internal c_str of data.
while (i<x){
j=50;
if((i+j)>x) j = x - i;
Client.write(&charptr[i],j); // starting at charptr[i] send then next j bytes.
i = i + j;
}
Client.println(); // send eol
Chuck.
Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.
IMHO the data string looks just fine and a POST request would certainly be able to handle it i.e. the length.
Unless the code is only partial, the OP does not have any libraries included for a start, so it will never work.
I also do not see a definition for the variable server etc etc.
So first question to OP - is the above your full code?
If not, please you should post the code in full if u hope to receive some objective help.
aisc:
IMHO the data string looks just fine and a POST request would certainly be able to handle it i.e. the length.
Unless the code is only partial, the OP does not have any libraries included for a start, so it will never work.
I also do not see a definition for the variable server etc etc.
So first question to OP - is the above your full code?
If not, please you should post the code in full if u hope to receive some objective help.
chucktodd:
Try breaking the data into smaller block.
i try to understand your code but i need time for this and need to write the server side code according to that i believe.Still don't understand why can't send and whats the max length for it or is this really the reason why i can't send
You are closing the connection before u actually send the request - FWIW I have seen many code examples written like this, but I would close the connection after sending the request.
For the errors, u need to log into cpanel and navigate to the directory the script is located in. You should find an error log file there, which should give you some clues.
Had a quick peek at your server... seems Windows hosted.
POST code I gave you I know works with Linux/Apache.
Not sure what mileage you will get trying to post to a Windows box.
Try it anyway...
aisc:
Had a quick peek at your server... seems Windows hosted.
POST code I gave you I know works with Linux/Apache.
Not sure what mileage you will get trying to post to a Windows box.
Try it anyway...
Because i am using asp.net.Post is working.Problem is its not working after some length(after Data8).I send post data Data0,1.....20 from Unity3d to same url and it worked and from that i think this is something to do with arduino.
I don't see how the sdcard will help, in terms of posting the data string to the server.
You could certainly write the data string to the sdcard.
You could even use the sdcard as a web server to serve up the data, but that would not be in the same league as a web based server.
char server[] = "arduinocontrol.somee.com"; // name address for Google (using DNS)
That is NOT google's address!
Why is it necessary to POST the data? The GET request is far simpler to use. There is NOTHING about the data that you are sending that makes it necessary to hide the data (that I can see).
char server[] = "arduinocontrol.somee.com"; // name address for Google (using DNS)
That is NOT google's address!
Why is it necessary to POST the data? The GET request is far simpler to use. There is NOTHING about the data that you are sending that makes it necessary to hide the data (that I can see).
yes its not.Because i was using example code to understand so forget to remove that comment.I don't want to hide the data u are right ,i just want to send the data.Even if i use query string do you think it will make any change? Because i am convinced this is about string length that i am using make me run out of Sram.
If you are afraid of running out of SRAM, then shorten the variable names.
// from this
String data="Finish=1&Data0=52&Data1=24&Data2=66&Data3=39&Data4=38&Data5=26&Data6=11&Data7=3&Data8=100&Data9=100";
// to this
String data="F=1&D0=52&D1=24&D2=66&D3=39&D4=38&D5=26&D6=11&D7=3&D8=100&D9=100";
SurferTim:
If you are afraid of running out of SRAM, then shorten the variable names.
// from this
String data="Finish=1&Data0=52&Data1=24&Data2=66&Data3=39&Data4=38&Data5=26&Data6=11&Data7=3&Data8=100&Data9=100";
// to this
String data="F=1&D0=52&D1=24&D2=66&D3=39&D4=38&D5=26&D6=11&D7=3&D8=100&D9=100";
edit: Here are my sketches on the playground. Both GET and POST.
http://playground.arduino.cc/Code/WebClient
Thank you for your help.Of course as a lazy person i thought that too but this is just an example even if i shorten them the max data i can send is 13.And need somehow to do chuck way or i need miracle to send 180 data.
SurferTim:
180 data variables? Where are you getting all that data?
I would use a SD card to store that string, but that is just me.
I have servo turning 180 degree and ultrasonic sensor sitting on it gathering data then i am sending those values.I believe chucks code is working.I will try it for 180 data and update my code.
I updated the code.Thanks to chuck for his help.Its possible to send data even its long such as 180 or more.Since it sends j bytes every time(still i am not really understand the code) even the long data is not problem.However again there is a really annoying problem about string length i encountered the code below;
There is a code that i take distance and write it to string.I take it from my full code and modified it to make it easier to understand.String yourdata ;updates every time and it should be able to hold a long string.However the variable inside of the string changes and when print to screen it shows D37=..D38=..
which should be D0=..D39=..When string is constant you can make it as long as you want and the limit is not really problem.You can define String yourdata="D0=....D180=" and there will be no problem.String also gives too much pain in terms of space and if its possible i will try not to use it.For now i want to know the reason causing this and how to hold this string data ?