Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Web client
- This sketch connects to a website (http://www.google.com)
- using an Arduino Wiznet Ethernet shield.
- Circuit:
- * Ethernet shield attached to pins 10, 11, 12, 13
- created 18 Dec 2009
- by David A. Mellis
- modified 9 Apr 2012
- by Tom Igoe, based on work by Adrian McEwen
- */
- #include <SPI.h>
- #include <Ethernet.h>
- // Enter a MAC address for your controller below.
- // Newer Ethernet shields have a MAC address printed on a sticker on the shield
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEE, 0xFE, 0xED };
- // if you don't want to use DNS (and reduce your sketch size)
- // use the numeric IP instead of the name for the server:
- //IPAddress server(83.143.132.2); // numeric IP for Google (no DNS)
- char server[] = "http://www.ewikuslugi.twojeuti.pl"; // name address for Google (using DNS)
- // Set the static IP address to use if the DHCP fails to assign
- IPAddress ip(192,168,1,110);
- // Initialize the Ethernet client library
- // with the IP address and port of the server
- // that you want to connect to (port 80 is default for HTTP):
- EthernetClient client;
- void setup() {
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for Leonardo only
- }
- // start the Ethernet connection:
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Failed to configure Ethernet using DHCP");
- // no point in carrying on, so do nothing forevermore:
- // try to congifure using IP address instead of DHCP:
- Ethernet.begin(mac, ip);
- }
- // give the Ethernet shield a second to initialize:
- delay(1000);
- Serial.println("connecting...");
- // if you get a connection, report back via serial:
- }
- void loop()
- {
- //if (client.connect(server, 80)) {
- //Serial.println("connected");
- // Make a HTTP request:
- // String data = "wiad=witam serdecznie" ;
- // if (client.connect("www.ewikuslugi.twojeuti.pl",80)) { // REPLACE WITH YOUR SERVER ADDRESS
- // client.println("POST /mailuj.php HTTP/1.1");
- // client.println("Host: www.ewikuslugi.twojeuti.pl"); // SERVER ADDRESS HERE TOO
- // client.println("Content-Type: application/x-www-form-urlencoded");
- // client.print("Content-Length: ");
- // client.println(data.length());
- // client.println();
- // client.print(data);
- // Serial.println(data.length()+data);
- // }
- // if (client.connected()) {
- // client.stop(); // DISCONNECT FROM THE SERVER
- // }
- // }
- // else {
- // kf you didn't get a connection to the server:
- // Serial.println("connection failed");
- // }
- postData();
- //Get();
- if (client.available()) {
- char c = client.read();
- Serial.print(c);
- }
- // if the server's disconnected, stop the client:
- if (!client.connected()) {
- Serial.println();
- Serial.println("disconnecting.");
- client.stop();
- // do nothing forevermore:
- while(true);
- }
- }
- void postData() {
- // Combine yourdatacolumn header (yourdata=) with the data recorded from your arduino
- // (yourarduinodata) and package them into the String yourdata which is what will be
- // sent in your POST request
- String nag = "wiad=";
- String wart ="costam";
- String yourdata = nag + wart;
- // If there's a successful connection, send the HTTP POST request
- if (client.connect(server, 80)) {
- Serial.println("connecting...");
- // EDIT: The POST 'URL' to the location of your insert_mysql.php on your web-host
- client.println("POST /mailuj.php HTTP/1.1");
- // EDIT: 'Host' to match your domain
- client.println("Host: http://www.ewikuslugi.twojeuti.pl");
- client.println("User-Agent: Arduino/1.0");
- client.println("Connection: close");
- client.println("Content-Type: application/x-www-form-urlencoded;");
- client.print("Content-Length: ");
- client.println(yourdata.length());
- client.println();
- client.println(yourdata);
- Serial.println(yourdata.length());
- Serial.println();
- Serial.println(yourdata);
- }
- else {
- // If you couldn't make a connection:
- Serial.println("Connection failed");
- Serial.println("Disconnecting.");
- client.stop();
- }
- }
- void Get(){
- if (client.connect(server, 80)) {
- Serial.println("connected");
- // Make a HTTP request:
- client.println("GET /index.php HTTP/1.1");
- client.println("Host: http://www.ewikuslugi.twojeuti.pl");
- client.println("Connection: close");
- client.println();
- }
- else {
- // kf you didn't get a connection to the server:
- Serial.println("connection failed");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement