Chat freely about anything...

User avatar
By pinktoadette
#13801 I am having trouble getting data. Everything seems to work but this part:
Code: Select allvoid loop() {
  connectWeb("TCP", HOST, PAGE, 443);
  requestPage(HOST, PAGE, 443);
  if(esp8266.find("+IPD"))
    Serial.print("found IPD");
   else Serial.print("cant find ipd");  //it shows me this...
}


And here;s the connectweb
Code: Select allString connectWeb(String type, String address, String page, int port)
{
  String cmd = "AT+CIPSTART=\"";
  String response;
  cmd += type;
  cmd += "\",\"";
  cmd += address;
  cmd += "\",\"";
  cmd += port;
  cmd += "\"";
  esp8266.println(cmd);
  Serial.println(cmd);
  delay(5000);

  while (esp8266.available()) {
    char c = esp8266.read(); // read the next character. this is because it prints one char at a time
    response += c;
    delay(50);
  }
  return response;
}


Requesting page
Code: Select all// Request a page from an HTTP server.
boolean requestPage(String host, String page, int port)
{
  // Create raw HTTP request for web page.
  String http_req = "GET " + page + " HTTP/1.1\r\nHost: " + host + ":" + port + "\r\n\r\n";

  // Ready the module to receive raw data.
  String cmd = "AT+CIPSEND=0,";
  cmd = cmd + http_req.length(); // Tell the ESP8266 how long the coming HTTP request is.
  Serial.print(cmd);
  Serial.println("requesting page...");
  sendData(cmd,1000);
}
User avatar
By CheapB
#13812 if you are willing to go the ESP Arduino route there is a good example included:

Code: Select all/*
 *  This sketch sends data via HTTP GET requests to data.sparkfun.com service.
 *
 *  You need to get streamId and privateKey at data.sparkfun.com and paste them
 *  below. Or just customize this script to talk to other HTTP servers.
 *
 */

#include <ESP8266WiFi.h>

const char* ssid     = "your-ssid";
const char* password = "your-password";

const char* host = "data.sparkfun.com";
const char* streamId   = "....................";
const char* privateKey = "....................";

void setup() {
  Serial.begin(115200);
  delay(10);

  // 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());
}

int value = 0;

void loop() {
  delay(5000);
  ++value;

  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;
  }
 
  // We now create a URI for the request
  String url = "/input/";
  url += streamId;
  url += "?private_key=";
  url += privateKey;
  url += "&value=";
  url += value;
 
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  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");
}