Advertisement
tvrtko282

Untitled

May 26th, 2015
266
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4.  
  5. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  6. char server[] = "www.etfos.unios.hr";
  7. //IPAddress ip(192,168,0,177);
  8. EthernetClient client;
  9.  
  10.  
  11. int networkCall(){
  12.   if (client.connect(server, 80)) {
  13.     String data="url=https://<page>";
  14.     Serial.println("connected");
  15.     client.println("POST /~<name>/my.php HTTP/1.1");
  16.     client.println("Host: www.etfos.unios.hr");
  17.     client.println("User-Agent: Arduino/1.0");
  18.     client.println("Connection: close");
  19.     client.println("Content-Type: application/x-www-form-urlencoded");
  20.     client.print("Content-Length: ");
  21.     client.println(data.length());
  22.     client.println();
  23.     client.println(data);
  24.     client.println();
  25.    
  26.    
  27.     delay(1000);
  28.    
  29.     //nakon ovog moras imati json
  30.     char char_array[500], result[500];
  31.     int i = 0;
  32.     while (client.available()) {
  33.       char c = client.read();
  34.       char_array[i] = c;
  35.       i++;
  36.     }
  37.    
  38.     char_array[i] = '\0';
  39.    
  40.     String str(char_array);
  41.    
  42.     Serial.println(str);
  43.     // if the server's disconnected, stop the client:
  44.     if (!client.connected()) {
  45.       Serial.println();
  46.       Serial.println("disconnecting.");
  47.       client.stop();
  48.     }
  49.   }
  50.   else{
  51.     Serial.println("connection failed");
  52.   }
  53. }
  54. void setup() {
  55.   Serial.begin(9600);
  56.       Serial.println("connecting...");
  57.    
  58.   if (Ethernet.begin(mac) == 0) {
  59.     Serial.println("Failed to configure Ethernet using DHCP");
  60.     // no point in carrying on, so do nothing forevermore:
  61.     // try to congifure using IP address instead of DHCP:
  62.     //Ethernet.begin(mac, ip);
  63.   }
  64. }
  65.  
  66. void loop() {
  67.   // put your main code here, to run repeatedly:
  68.   Serial.println("Network call");
  69.   networkCall();
  70.   Serial.println("Network call end");
  71. }
Advertisement
RAW Paste Data Copied
Advertisement