Skip to main content

You are here

Home » Forums » General discussion

Ether Card and how to post data to local server on another port

11 posts / 0 new
Last post
Thu, 2011-12-15 17:18
#1
gjniewenhuijse
Ether Card and how to post data to local server on another port

Hello,

Instead of writing my Roomnode output to the serial port i like to post it on a local webserver (ip 192.168.0.57 and port 8900).

I can post the data in an url like:
192.168.0.57:8900/SendData?id=1&data=OK 72 4 44 0 17

Can u use ether.browseUrl or is there a better way to post the data?
ether.browseUrl(PSTR("/SendData"), "?id=1&data=OK 72 4 44 0 17", ??, my_callback);

How to use browseUrl with an ipadress instead of an hostname?
And how to set port 8900 instead of 80?

Top
Thu, 2011-12-15 23:26
#2
jcw

How to use browseUrl with an ipadress instead of an hostname?

Try this:

ether.hisip[0] = 192; ether.hisip[1] = 168; ether.hisip[2] = 0; ether.hisip[3] = 57

Then pass PSTR("192.168.0.57") to browseUrl (the empty string probably works as well there).

And how to set port 8900 instead of 80?

Try this:

ether.hisport = 8900;

(haven't tried it - and this stuff will need to be documented if it works, of course)

Top
Thu, 2011-12-15 23:54
#3
Osray

I just was working on a similar thing. I started with the ethernode sketch and then modified it. Here are the most important parts:

// Static IP configuration to use if no DHCP configured
// Change these to match your site setup
static byte static_ip[] = { 192,168,210,182 }; //local
static byte static_gw[] = { 192,168,210,1 };
static byte static_dns[] = { 192,168,0,2 };
static byte hisip[] = { 192,168,210,181 }; // remote webserver
[...]

setup()
{
[...]
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");

#ifdef USE_DHCP
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#else

ether.staticSetup(static_ip,static_gw,static_dns);
ether.copyIp(ether.hisip, hisip);
[...]
}

void sendDataToWebserver( byte const *data, int dataLen )
{
Serial.println("sending packet");
char paramString[128];
int i;
for( i=0; i<dataLen; i++ )
{
sprintf( &(paramString[i*3]), "%.3d", data[i] );
}
ether.browseUrl(PSTR("/updateStatus.cgi?"), paramString, website, browserresult_callback);
}

Then in the loop()-Function i added something like:

[...]
msgs_rcvd = (msgs_rcvd + 1) % 10000;
sendDataToWebserver( (const byte*) rf12_data, rf12_len );
if (RF12_WANTS_ACK && !config.collect)
[...]

I also patched the port in tcpip.cpp,EtherCard::browseUrl from 80 to 8080:
www_fd = clientTcpReq(&www_client_internal_result_cb,&www_client_internal_datafill_cb,8080);

This is not a clean solution! Its a dirty hack. It was just a proof-of-concept for me. Above code contains several issues, eg. there is a possible buffer overflow the way i use sprintf. The whole thing was just tested until i saw data in wireshark looking like a GET request with some payload in it.
You also want to let the RFM send the ack the to the paket, so the receiver gets it as fast as possible, but i think the receive-buffer is reused for sending out the reply, so you'd have to copy it to a temp buffer before. I will clean this up the next days and then i can provide something like a Radio-to-HTTP sketch.

Cheers, Rainer

Top
Fri, 2011-12-16 09:15
(Reply to #3) #4
gjniewenhuijse

Thank you very much and please let me know if you have a new/better version of your Radio-to-HTTP sketch, i like to use exactly the same piece of code.

And JCW: "ether.hisport = 8900" doesn't work, only modifying the tcpip.cpp works but thats not a nice solution.

Top
Fri, 2011-12-16 10:32
#5
Osray

Maybe its possible to add an optional parameter "destinationPort=80" to browseUrl(...); that one can overwrite when needing a non-standard port? This would be nice as spawning a server on "privileged" port 80 ( all <1024) requires superuser-permissions.

Top
Fri, 2011-12-16 11:26
(Reply to #5) #6
gjniewenhuijse

Yes i think thats a good idea.

JCW, is it possible to add this to the standard library and maybe also add Radio-to-HTTP code to the ethernode sketch. I think a lot of people like this code.

Top
Fri, 2011-12-23 08:27
(Reply to #3) #7
gjniewenhuijse

Hello, do you like to share your complete Radio-to-HTTP sketch? Any maybe you have already an cleaned up version?

Many thanks..

Top
Fri, 2011-12-23 11:04
#8
Osray

Hi, i am currently testing my code. I had a version running that did POST requests similiar to the GET requests in the pachube-sketch, but that crashed every few hours. It seems that the reason was the usage of two stashes (with the first one getting inserted into the second, replacing a placeholder). Now i use normal strings and the sketch runs since a couple of days without problems. Its not yet cleaned up or documented, but i can upload it this evening. I'll post a link when its online.

~ Rainer

Top
Fri, 2011-12-23 16:08
(Reply to #8) #9
gjniewenhuijse

thank you very much.

I'm also looking to the JeeUDP example, here the data is posted to a server with UDP packets.

Top
Fri, 2011-12-23 20:09
(Reply to #9) #10
Osray

Ok, so here is my Main Sketch pastebin.com/Uq5DMaXg. I use it on a Pollin NetIO Board and it transmits received PDUs to a webserver. You'll need to adapt it to your needs, but maybe it can serve as a template.

I also uploaded the RadioPDU class files for completeness: .h: pastebin.com/VPX3tTLa .cpp: pastebin.com/NXfPcFRi

Top
Sat, 2011-12-24 16:11
(Reply to #10) #11
gjniewenhuijse

Thank you.

Nice work for my christmas days :)

Top
Premium Drupal Themes by Adaptivethemes
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.