×

Doing some holiday shopping? Please check here for shipping deadlines to make sure your order arrives in time.

Foggy

Member Since: July 9, 2011

Country: Australia

  • HI all, I have had the same issues as described here when I tried to send data, I have taken the code, tested every different possibilities and solutions and came up with a working piece of code here. Feel free to use it and please comment back to let me know how it performed for you. Make sure you write down your public key and your private key at the beginning of the sketch where it is written in bewteen the " " (YOUR PUBLIC KEY HERE and YOUR PRIVATE KEY HERE). Your Xbee needs to be configurated prior to this with X-CTU to be connected on your WiFi already.

    #include <SoftwareSerial.h>
    #include <stdlib.h>
    
    String server = "data.sparkfun.com";
    String publicKey = "YOUR PUBLIC KEY HERE";
    String privateKey = "YOUR PRIVATE KEY HERE";
    #define IP "54.86.132.254" // data.sparkfun.com
    SoftwareSerial xb(2, 3); // RX, TX
    const byte VALUES = 4;
    enum field_labels {SV, BV, CC, OC};
    const String Names[VALUES] = {"&solar_voltage=","&battery_voltage=","&charge_current=","&output_current="};
    float Data[VALUES];
    boolean battery_Charged = true;
    void setup()
    {
      xb.begin(9600);
    }
    
    void loop(){
    
      Data[SV] = analogRead(A0)/1024.00 * 30.00;
      Data[BV] = analogRead(A1)/1024.00 * 30.00;
      Data[CC] = analogRead(A2)/1024.00 * 10.00;
      Data[OC] = analogRead(A2)/1024.00 * 10.00;
    
      char buffer[7];
    
      xb.flush(); // Flush data so we get fresh stuff in
    
      xb.print("GET /input/");
      xb.print(String(publicKey));
      xb.print("?private_key=");
      xb.print(String(privateKey));
    
      for (int j=0; j<VALUES; j++)
      {
      xb.print(Names[j]);
      dtostrf(Data[j], 3, 2, buffer);
        for(int i=0;i<sizeof(buffer);i++)
      {
        xb.print(String(buffer[i]));
      }
    }
    
      xb.print("&battery_charged=");
      xb.print(String(battery_Charged));
    
      xb.println(" HTTP/1.1");
      xb.print("Host: ");
      xb.println(server);
      xb.println("Connection: close");
      xb.println();
      delay(10000);
    }
    

No public wish lists :(