Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This demo does web requests via DNS lookup, using a fixed gateway.
- // 2010-11-27 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
- #include <EtherCard.h>
- // ethernet interface mac address
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
- // ethernet interface ip address
- static byte myip[] = { 10,250,0,218 };
- // gateway ip address
- static byte gwip[] = { 10,250,0,254 };
- //dns
- static byte dns[] = { 10,250,0,2 };
- // remote website name
- const char website[] PROGMEM = "hexium-automation.lan.timstallard.me.uk";
- byte Ethernet::buffer[300]; // a very small tcp/ip buffer is enough here
- boolean button5 = 0;
- boolean button6 = 0;
- boolean button7 = 0;
- static long timer;
- // called when the client request is complete
- static void my_result_cb (byte status, word off, word len) {
- Serial.print("<<< reply ");
- Serial.println((const char*) Ethernet::buffer + off);
- }
- void setup () {
- Serial.begin(57600);
- Serial.println("\n[getViaDNS]");
- if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
- Serial.println( "Failed to access Ethernet controller");
- ether.staticSetup(myip, gwip, dns);
- if (!ether.dnsLookup(website))
- Serial.println("DNS failed");
- ether.printIp("Server: ", ether.hisip);
- pinMode(5, INPUT_PULLUP);
- pinMode(6, INPUT_PULLUP);
- pinMode(7, INPUT_PULLUP);
- }
- void loop () {
- ether.packetLoop(ether.packetReceive());
- if(millis() > timer + 1000){
- if(digitalRead(5) == LOW){
- if(button5 == 0){
- button5 = 1;
- Serial.println("Awake");
- timer = millis();
- ether.browseUrl(PSTR("/completeaction.php"), "?module=Scheduler&action=Awake", website, my_result_cb);
- }
- }
- else
- {
- button5 = 0;
- }
- if(digitalRead(6) == LOW){
- if(button6 == 0){
- button6 = 1;
- Serial.println("Arrived");
- timer = millis();
- ether.browseUrl(PSTR("/completeaction.php"), "?module=Scheduler&action=Arrived", website, my_result_cb);
- }
- }
- else
- {
- button6 = 0 ;
- }
- if(digitalRead(7) == LOW){
- if(button7 == 0){
- button7 = 1;
- Serial.println("Leaving");
- timer = millis();
- ether.browseUrl(PSTR("/completeaction.php"), "?module=Scheduler&action=Leaving", website, my_result_cb);
- }
- }
- else
- {
- button7 = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement