Help to send HTTP GET from opensprinkler TO my web server (to a .php script).

906 views
Skip to first unread message

got1

unread,
Oct 2, 2012, 10:22:18 AM10/2/12
to rays...@googlegroups.com
Hi Ray,

I have a web server on my LAN at 192.168.0.4

The web server has a php script (eg. 192.168.0.4/script.php?station=sn1&state=0) that logs data to a mysql table and issues a UDP broadcast of the data so that my HA system can update it’s status.

The plan is to alter your code so that everytime the sprinkler state change, it sends a GET ie. 192.168.0.4/script.php?station=sn1&state=0

To do this I would use the following code snippet to send “someString” to the php script.

//…other Ethernet setup code would go here…

// remote website ip address and port

static byte hisip[] = { 192,168,0,4 }; ether.copyIp(ether.hisip, hisip);

// called when the client request is complete
static void my_result_callback (byte status, word off, word len) {
Serial.print("<<< reply ");
Serial.println((const char*) Ethernet::buffer + off);
}

// someString in this example would be “script.php?station=sn1&state=0”
// Somewhere in the code where I want to do the actual call
ether.packetLoop(ether.packetReceive());

ether.browseUrl(PSTR("/script.php?"), someString, NULL, my_result_callback);

However I note that hisip is aleady assigned in your code.

Are you able to help me with the code I would use to send a simple http Get from Opensprinkler to a fixed IP on my LAn (192.168.0.4).

Once I get it working I will post the code on your

Thank

Ray

unread,
Oct 3, 2012, 9:01:08 AM10/3/12
to rays...@googlegroups.com
Are you sure hisip is assigned in my code? I can't find where it is assigned. 

got1

unread,
Oct 4, 2012, 5:17:45 AM10/4/12
to rays...@googlegroups.com
Hi Ray...it is set in dns.cpp...but perhaps you do not use it and it's just a part of the library.

I'll have a play with the code and see what happens.

I am not familiar with thesen Ethernet libraries, I use an Ethernet library for an EtherShield normally and these ones for the ethercard are very different.

thanks.

Ray

unread,
Oct 4, 2012, 9:03:46 AM10/4/12
to rays...@googlegroups.com
You are right, dns.cpp is part of the library.

Indeed the EtherCard library is very different from Arduino EtherShield. You can check the examples that come with EtherCard to learn how to use it.

Andrew Radke

unread,
Oct 4, 2012, 10:33:16 PM10/4/12
to rays...@googlegroups.com
This could actually be a very good way of implementing a logging service. There was a previous thread regarding using syslog and while I would prefer that functionality it doesn't help Windows users.

And using HTTP would relatively easily allow for sending things like changed configuration. Making it a configurable setting from within the options page could mean it would be changeable as well so it wouldn't be locked to one particular environment.

Ray, is it something that you would consider adding as a feature?

Regards,
Andrew

Ray

unread,
Oct 4, 2012, 10:46:14 PM10/4/12
to rays...@googlegroups.com
Sorry I didn't quite understand your question. If you are asking whether you can use http get command to set option values, there is already a way. All web commands are implemented using http get. When you submit changes in the options page, just look at the url in your browser. That's the command being sent to the controller. However, setting option values this way is a bit obscure because it currently requires knowing the index of each option. 

got1

unread,
Oct 5, 2012, 1:35:33 AM10/5/12
to rays...@googlegroups.com
I think he is referring to logging of commands via opensprinkler issuing http get's on a change of state.

ie. sprinkler 1 turns on and the arduino code issues a http get to a user defined URL with the change of state.

this is what I am planning to do in the code, I think Andrew is suggesting this be exposed in the GUI to allow easy user config. ie. enter the URL of the php script and opensprinkler append the state change as a parameter to this URL and initiates the get.

ie opensprinkler sends a http GET to 192.168.0.4/script.php?station=sn1&state=0 

cheers

 


Andrew Radke

unread,
Oct 5, 2012, 8:00:39 AM10/5/12
to rays...@googlegroups.com
Yes, sorry I should've been clearer. I am only talking about logging.

First off logging state changes but then also logging configuration changes as well is very useful for being able to go back and work out what happened when.

Syslog would be ideal since that is pretty much the whole point of it, but it might limit it's target audience. Then again since most routers, etc support logging via it these days maybe it's not as unusual as I might think.

Andrew

Ray

unread,
Oct 7, 2012, 5:32:31 PM10/7/12
to rays...@googlegroups.com
I see. One thing that came into my mind is that it should be possible to send logging data to google docs. I've seen some Arduino projects that use get commands to send logging data to google docs. It should be straightforward to do the same for opensprinkler. The only thing I need to check is whether the remaining program memory space is sufficient to implement this.

Andrew Radke

unread,
Oct 9, 2012, 11:11:04 PM10/9/12
to rays...@googlegroups.com
Hi Ray,

The more I've been thinking about this the more I think that using syslog is a better general solution. Being UDP it won't cause any problems if the remote server isn't responding and these days it is such a standard that I'm sure there must also be syslog servers for Windows. It is a problem that has already been solved and reinventing the wheel through HTTP might not be the best solution.

But Google Docs might be something that others prefer too...

Andrew

got1

unread,
Oct 10, 2012, 3:04:45 AM10/10/12
to rays...@googlegroups.com
Agree UDP would be best...I would infact prefer to use a UDP broadcast message, but was never able to get it to work with my other arduino ethershield. Perhaps this ethernet library does broadcast?

Either way, I guess I could just make it udp to a single ip and have that do the broadcast (this is what I do now anyway with the http GET).

cheers,

ps...about to try and recover my opensprinkler board :)

got1

unread,
Oct 10, 2012, 9:22:45 AM10/10/12
to rays...@googlegroups.com
Well, the code for UDP is pretty simple...eg. this cutdown sketch send a hello world packet and works perfectly when uploaded to the opensprinkler.

The problem is twofold...
1. there isnot enough space left on the Arduino to add even this basic code to opensprinkler.
2. it seems to have some sort of issue with the rest of the code and does not issue the UDP broadcast when I added it to the button press section of opensprinkler...perhaps the webserver ?

Anyone else want to have a play and see if you can get UDP packets sent from opensprinkler?

#include <EtherCard.h>

byte mymac[] = { 0x00,0x69,0x69,0x2D,0x30,0x30 }; // mac address
byte ipMy[] = {192, 168, 0, 73};
uint8_t broadcast
[4] = { 255,255,255,255};
byte ipGateway[] = {192, 168, 0, 254};

unsigned int portMy = 8888;
unsigned int portDestination = 8888;

byte Ethernet::buffer[220];

char msg[] = {"Hello World"};

void setup() {
  ether
.begin(sizeof Ethernet::buffer, mymac);
    ether
.staticSetup(ipMy, ipGateway);

}

void loop() {
  delay
(1000);
  ether
.sendUdp(msg, sizeof msg, portMy, broadcast, portDestination);
}


Reply all
Reply to author
Forward
0 new messages