loading

problem with making my Arduino Ethernet shield to communicate with the server

I have a problem making my Arduino Ethernet shield to communicate with the server, the result on the serial monitor is always:

Not connected
Cannot connect to Server


#include <SPI.h>
#include <Ethernet.h>
//-------------------------------------------------------------------------------
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC Address
char server[] = "api.pushingbox.com"; //pushingbox API server
IPAddress ip(192,168,1,2); //Arduino IP address. Only used when DHCP is turned off.
EthernetClient client; //define 'client' as object
String data; //GET query with data
float temp; //temp means temperature
boolean cste = false;
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
  }
  delay(1000);
}
//------------------------------------------------------------------------------
void loop(){
   int temp_ADC = analogRead(0); //read analog input on pin A0
   temp = temp_ADC * 5.0 * 100.0/1024.0; // ADC to celcius conversion
   tempData(); //packing GET query with data
   Serial.println("connecting...");
   if (client.connect(server, 80)) {
     sendData(); 
     cste = true; //connected = true
   }
   else{
     Serial.println("connection failed");
   }
  // loop
  while(cste){
    if (client.available()) {
   char c = client.read(); //save http header to c
   Serial.print(c); //print http header to serial monitor
    }
    if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
          Serial.print("Temperature Sent :");
          Serial.println(temp); //print sent value to serial monitor
   client.stop();
          cste = false;
          data = ""; //data reset
    }
  }
  delay(5000); // interval
}

void tempData(){
  data+="";
  data+="GET /pushingbox?devid=vB917B251887BF54&tempData="; //GET request query to pushingbox API
  data+=temp;
  data+=" HTTP/1.1";
}
void sendData(){
  Serial.println("connected");
  client.println(data);
  client.println("Host: api.pushingbox.com");
  client.println("Connection: close");
  client.println();
}

SoufianeG (author) 1 year ago

thanks a lot

Read through this ible that might help. Note that there might be some changes to account for since that was done about a year ago. You need to configure the service and have accounts running. Good luck.

https://www.instructables.com/id/Post-to-Google-Docs-with-Arduino/