Hi,
I want to modify emonBase to post to emoncms.com.as per normal and a second http GET to a custom PHP script on my local network. I have added the following line of code to the emonBase sketch. However it doesn't work. From what I can tell it has to do with the fact that I am specifying an IP address rather than a DNS name. I can't find much documentation on browseURL to figure out how to specify an IP address in the third argument of the following line.
ether.browseUrl(PSTR("") ,"/monitoring/water.php?litres=0.5&flowrate=1.0", "192.168.252.30" , my_callback);
I have tested my code by setting use_hisip to true and specifying my IP address as the hisip address. However this has the side effect of using the internal address for the second post to emonCMS rather than using emoncms.com. Any thoughts.
Re: Posting to local server
If use_hisip is true, which you need for local addressing as you don't have a local DNS, both the first and third arguments to browseURL are unused, and the IP address makes its way in via hisip[ ]; then it gets copied into ether.hisip with a call to ether.copyIp(ether.hisip, hisip); in dhcp_dns().
So it looks to me as if you'll need to plug the IP address into ether.hisip separately and set use_hisip differently before each call to browseURL. Whether you need to save the emoncms.org IP address out of ether.hisip first, I don't know.
Hope that helps.
Re: Posting to local server
Thanks. Great idea. I tried the following but didn't have any luck.
byte hisip_old[4];
for (int i = 0; i<5; ++i){
hisip_old[i] = ether.hisip[i];
}
static byte hisip_local[] = { 192,168,252,30 };
ether.copyIp(ether.hisip, hisip_local);
ether.browseUrl(PSTR("") ,"/monitoring/water.php?litres=0.5&flowrate=1.0", NULL , my_callback);
ether.copyIp(ether.hisip, hisip_old);
Maybe I'm approaching it the wrong way.
Re: Posting to local server
Don't you need to set use_hisip to false to use the URL, and to true to use the IP? I've not played with this - I will try to give it a go tomorrow.
N.B. Aren't you writing past the end of the array with "for (int i = 0; i<5; ++i){ "
Re: Posting to local server
Hi Robert,
I've got use_hisip set to true and then are substituting the IP address of the emoncms.org server with my internal server as above. From what I can tell it should work.
You're right. There is a problem with the index on the array. I've fixed that but still no good.
Re: Posting to local server
Hmmm. This is proving difficult. I've run into all manner of problems, out of memory, spotted a probable bug in the PacketBuffer class, now browseURL appears to picking up the wrong string despite the parameter passed to it being correct. But progress is being made: I'm posting to emoncms.org and getting the time from my local WAMP server.
Re: Posting to local server
Thanks for looking into this Robert. Have you found anything that you would like to share?
Re: Posting to local server
Apart from adding my moan about the apparent absence of meaningful documentation - not yet! (The phrase 'going off at half-cock' comes to mind.) There's a lot going on inside the Ethercard library that is less than clear at the moment. When I've got it sorted and understand why what I'm doing works, then I'll document and publish.
Re: Posting to local server
Sounds great.I am facing a similar task here, so I will eagerly await your findings.
Re: Posting to local server
I completely agree re the lack of documentation. It is very frustrating. Thanks again Robert.
Re: Posting to local server
I am still struggling. In essence, what I have is three sections of code:
I can do 1 & 3 or 2 & 3.
If I enable both 1 & 2, then it does 2 & 3. If I reverse the order of 1 & 2, (i.e. 2 - 1 - 3) it does 1 & 3, i.e the last one plus 3. You might expect inserting a delay or an extra
to make a difference - it doesn't.
There's this comment in the library code: "packetLoop(), unfortunately, is strange and undocumented." It doesn't exactly inspire confidence.
Re: Posting to local server
A breakthrough - the solution is in sight.
It appears that it is necessary to wait for 'ok' to come back from the first server before issuing the GET (aka BrowseUrl) to the second server. The time request to a different server worked because most of the time, the 'ok' response had been received, but this appears to be entirely fortuitous.
The problem now is how to handle timeouts if one server fails to respond. Clearly, it must not lock up and it ought to carry on sending to the second server, and I suppose send an equivalent to the "rf fail" message?