Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EtherCard.h>
- // Define Static IP
- #define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
- // if static use this :
- #if STATIC
- // ethernet interface ip address
- static byte myip[] = { 192,168,1,2 };
- // gateway ip address
- static byte gwip[] = { 192,168,1,1 };
- #endif
- // Variables
- // ethernet mac address - must be unique on your network
- static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
- const char website[] PROGMEM = "192.168.2.5";
- byte Ethernet::buffer[700];
- uint32_t timer;
- Stash stash;
- int uidvalue = 1; // gone for simplicty
- int busyvalue = 1; // gone for simplicity
- /*
- * Setup config
- */
- void setup() {
- //netwerk
- Serial.begin(57600);
- Serial.println("\n[Starting up network]");
- if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
- Serial.println( "Failed to access Ethernet controller");
- #if STATIC
- ether.staticSetup(myip, gwip);
- #else
- if (!ether.dhcpSetup())
- Serial.println("DHCP failed");
- #endif
- ether.printIp("IP: ", ether.myip);
- ether.printIp("GW: ", ether.gwip);
- ether.printIp("DNS: ", ether.dnsip);
- }
- /*
- * Loop config
- */
- void loop() {
- ether.packetLoop(ether.packetReceive());
- if (millis() > timer) {
- timer = millis() + 10000;
- // generate two fake values as payload - by using a separate stash,
- // we can determine the size of the generated message ahead of time
- byte sd = stash.create();
- stash.print("0,");
- stash.println((word) millis() / 123);
- stash.print("1,");
- stash.println((word) micros() / 456);
- stash.save();
- // generate the header with payload - note that the stash size is used,
- // and that a "stash descriptor" is passed in as argument using "$H"
- Stash::prepare(PSTR("http://192.168.2.5/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
- "Host: 192.168.1.1" "\r\n"
- "Content-Length: $D" "\r\n"
- "\r\n"
- "$H"),stash.size(), sd);
- ether.tcpSend();
- Serial.print("tcp package send ");Serial.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement