NewSoftSerial library .. .what is wrong?
hi,
i have ethernet shield xport direct+ on it.
i run example, guess hardware side ok.
i trying post request web server using code:
so masked personal values, trust me correct.... guess what, not true, appears ip not static @ all, when thought was... have install web server , try again ...
this piece of code trying connect web server, write post request:
the reset works, connect not , other parts of code, can see wrong?
thanks
i have ethernet shield xport direct+ on it.
i run example, guess hardware side ok.
i trying post request web server using code:
code: [select]
#include <newsoftserial.h>
#define php_page_location "/test.php"
#define web_host "host: mywebsite.free.fr\n"
#define ip_and_port "c2xx.27.x3.yyy/80\n"
#define xport_rxpin 2
#define xport_txpin 3
#define xport_resetpin 4
#define xport_dtrpin 0
#define xport_ctspin 0
#define xport_rtspin 0
newsoftserial xportserial(xport_txpin, xport_rxpin);
void setup()
{
serial.begin(9600);
serial.println("ready?");
// set data rate newsoftserial port
xportserial.begin(9600);
int ver = newsoftserial::library_version();
serial.println(ver);
}
void loop() // run on , on again
{
serial.println("saving...");
save_data();
serial.println("done");
delay(30000);
}
void save_data() {
int i=0;
char json[328];
sprintf(json,"{\"log\":{\"ac_relays\":[{\"id\":0,\"value\":%d},{\"id\":1,\"value\":%d},{\"id\":2,\"value\":%d},{\"id\":3,\"value\":%d}],\"dc_relays\":[{\"id\":0,\"value\":%d},{\"id\":1,\"value\":%d},{\"id\":2,\"value\":%d},{\"id\":3,\"value\":%d}],\"ds18b20\":[{\"id\":0,\"value\":%.1f},{\"id\":1,\"value\":%.1f},{\"id\":2,\"value\":%.1f}],\"water_level\":[{\"id\":0,\"value\":%4d},{\"id\":1,\"value\":%4d}]}}",0,1,0,1,1,2,1,0,25.1,22.3,27.6,3,0);
httppost(json);
}
void xportconnect()
{
byte thebyte = 0;
xportserial.print(ip_and_port);
while (thebyte != 'c')
{
thebyte = (char)xportserial.read();
}
}
void xportreset()
{
pinmode(xport_resetpin, output);
digitalwrite(xport_resetpin, low);
delay(100);
digitalwrite(xport_resetpin, high);
delay(3000);
serial.println("reset done");
}
void httppost(char* json) {
byte thebyte = 0;
int len = strlen(json);
xportreset();
xportconnect();
serial.println("connected");
xportserial.print("post ");
xportserial.print(php_page_location);
xportserial.print(" http/1.1\n");
xportserial.print(web_host);
xportserial.print("user-agent: mozilla/4.0\n");
xportserial.print("content-length: ");
xportserial.print(len);
xportserial.print("\n");
xportserial.print("content-type: application/octet-stream\n");
xportserial.print("\n");
xportserial.print(json);
while(!xportserial.read()) {} // loop until available
serial.println(xportserial.read());
serial.println(json);
}so masked personal values, trust me correct.... guess what, not true, appears ip not static @ all, when thought was... have install web server , try again ...
this piece of code trying connect web server, write post request:
code: [select]
cxxx.yyy.zzz.ttt/80
wait...and print
post /test.php http/1.1
host: xxxxx.free.fr
user-agent: mozilla/4.0
content-length: 318
content-type: application/octet-stream
{"log":{"ac_relays":[{"id":0,"value":0},{"id":1,"value":1},{"id":2,"value":0},{"id":3,"value":1}],"dc_relays":[{"id":0,"value":1},{"id":1,"value":2},{"id":2,"value":1},{"id":3,"value":0}],"ds18b20":[{"id":0,"value":?},{"id":1,"value":?},{"id":2,"value":?}],"water_level":[{"id":0,"value": 3},{"id":1,"value": 0}]}}the reset works, connect not , other parts of code, can see wrong?
thanks
hi,
ok, after testing, using now:
- pin cls
- af_xport library
it works fine 'get' on google.com, quite unstable company hosting web site, , main reason of failure have seen... need find more liable solution.
ok, after testing, using now:
- pin cls
- af_xport library
it works fine 'get' on google.com, quite unstable company hosting web site, , main reason of failure have seen... need find more liable solution.
Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > NewSoftSerial library .. .what is wrong?
arduino
Comments
Post a Comment