0

I am trying to send data from Analog Sensor 1 on the arduino yun to a spreadsheet in google docs via pushingbox.com. So I have got the ling between pushingbox and the google docs working but its the link between the Yun and the pushingbox that I am struggling with. I have connected the Yun via ethernet to the net and that connection is working fine.

The MAC Address and IP have been changed from my original. Can't seem to find why this code is not working. It just says "connecting..." on the serial monitor. Below I have pasted my code.

Someone please help me.

#include <SPI.h>
#include <Ethernet.h>

//-------------------------------------------------------------------------------
byte mac[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; //Setting MAC Address
char server[] = "api.pushingbox.com"; //pushingbox API server
IPAddress ip(000,000,000,00); //Arduino IP address. Only used when DHCP is turned off.
EthernetClient client; //define 'client' as object
String data; //GET query with data
float suhu; //suhu (bahasa Indonesia) means temperature
boolean koneksi = 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 baca_ADC = analogRead(1); //read analog input on pin A1
   suhu = baca_ADC * 5.0 * 100.0/1024.0; // ADC to celcius conversion
   kemasData(); //packing GET query with data
   Serial.println("connecting...");
   if (client.connect(server, 80)) {
     sendData();  
     koneksi = true; //connected = true
   }
   else{
     Serial.println("connection failed");
   }
  // loop
  while(koneksi){
    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(suhu); //print sent value to serial monitor
    client.stop(); 
          koneksi = false; 
          data = ""; //data reset
    }
  }
  delay(5000); // interval
}

void kemasData(){
  data+="";
  data+="GET /pushingbox?devid=xxxxxxxxxxxxxxxx&tempData="; //GET request query to pushingbox API
  data+=suhu;
  data+=" HTTP/1.1";
}
void sendData(){
  Serial.println("connected");
  client.println(data);
  client.println("Host: api.pushingbox.com");
  client.println("Connection: close");
  client.println();
}
pnuts
  • 58,317
  • 11
  • 87
  • 139

1 Answers1

0

I think your code is stuck at while() loop, are you getting connecting...... continuously written every 5 seconds or only once? if once then I think this is definitely the while loop()

Naaz
  • 273
  • 2
  • 6
  • 21