Chat freely about anything...

User avatar
By basit701
#60644 Hello Guys i have written a code to read data from RX (ESP8266) and transmit it to freeboard.io . But the problem is that:

Code: Select all b=String("GET /dweet/for/uetmpsproject?temperature=") + String(t) + String("&humidity=") + String(a) + String(" HTTP/1.1\r\n") + String("Host: ") + host + String("\r\n") + String("Connection: close\r\n\r\n");
  client.print(b);


does not execute when serial data is read. i.e (when RX buffer gets some data from sensor).

the code is:

Code: Select all// Import required libraries
#include "ESP8266WiFi.h"

// WiFi parameters
const char* ssid = "TP-LINK_4A8154";
const char* password = "honda125";

// Host
const char* host = "dweet.io";
int temp = 0;

String a;
String b;
void setup() {
 
  // Start Serial
  Serial.begin(115200);
  delay(10);
 
  // Init DHT
  //dht.begin();

  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
 temp = temp +1;

  Serial.print("Connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
  a = Serial.readString();
 delay(20);
 
  int t = temp;     
 
  // This will send the request to the server
 b=String("GET /dweet/for/uetmpsproject?temperature=") + String(t) + String("&humidity=") + String(a) + String(" HTTP/1.1\r\n") + String("Host: ") + host + String("\r\n") + String("Connection: close\r\n\r\n");
  client.print(b);
  delay(10);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Serial.println("closing connection");
  // Repeat every 10 seconds
  delay(10000);
 
}