SparkFun free data storage

@Amakaruk, It seems that you didn’t declare the TCPClient, the code is only the function to send data to Sparkfun Data. You should declare the TCPClient. The following code should work, please not that you should have include the DHT library.

// This #include statement was automatically added by the Spark IDE.
#include "DHT.h"

#define DHTPIN D4
#define DHTTYPE DHT22  

#define SPARKFUN_DATA_URL "data.sparkfun.com"
#define SPARKFUN_DATA_PORT 80
#define SPARKFUN_INPUT_PATH "input"
#define PRIVATE_KEY "qzz8b4BBdEs5EaY4YgBR"
#define PUBLIC_KEY "g66mX3rroWuDAQ7q7KJx"
#define STREAM_NAME "temperature"

DHT dht(DHTPIN, DHTTYPE);
TCPClient client;
int delaySend = 60 * 1000;


void setup() {
    pinMode(D7, OUTPUT);
    Serial.begin(115200);
    dht.begin();
    
    Serial.println("Ready, start sending data to Sparkfun.");
    digitalWrite(D7, HIGH);
}

void loop() {
    Serial.print("Sending data to Sparkfun...");
    sendToSparkfunData(dht.readTemperature());
    Serial.println(", Completed");

    delay(delaySend);
}

void sendToSparkfunData(float temperature){
    char szData[16];

    if(client.connect(SPARKFUN_DATA_URL, SPARKFUN_DATA_PORT)){
        sprintf(szData, "%.2f", temperature);
        
        client.print("GET /");
        client.print(SPARKFUN_INPUT_PATH);
        client.print("/");
        client.print(PUBLIC_KEY);
        client.print("?");
        client.print("private_key=");
        client.print(PRIVATE_KEY);
        client.print("&");
        client.print(STREAM_NAME);
        client.print("=");
        client.println(szData);
        client.print("Host: ");
        client.println(SPARKFUN_DATA_URL);
        client.println("Connection: close");
        client.println();
        
        client.flush();
        
        while(client.available()){
            sprintf(szData, "%c", client.read());
            
            Serial.print(szData);
        }
        
        client.stop();
    }
    else{
        Serial.println("Cannot connect to Sparkfun Data");
    }
}
1 Like