Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By popngood
#36537 Hello everyone,

I am having trouble setting my ESP8266 to station mode. I have already set the default WIFI mode to station mode using AT command AT+CWMODE=1. However, when I load my program using the Arduino IDE, an ESP8266 access point appears. :? :? :? :? :?

Code: Select all#include <OneWire.h>
#include <ESP8266WiFi.h>
void setupTemp(void);
void getTemp(void) ;
String APIkey = "RQFT5KELVIA8HGRP";
const char* ssid = "G2_8792";
const char* password = "123456789";
const char* host = "api.thingspeak.com";
const int httpPort = 80;

//float otemp;
float temp;

//DHT dht(DHTPIN, DHT11,15);
WiFiClient client;
   
void setup() {               
  Serial.begin(115200);
  setupTemp();
  delay(10);
 
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
   
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  Serial.print("The temperature is: ");
  getTemp();
  Serial.println(temp);

  Serial.print("The temperature is: ");
  getTemp();
  Serial.println(temp);
}
 
 
void loop() {
//===================================================================================================================== 
  Serial.print("connecting to ");
  Serial.println(host);
  // Use WiFiClient class to create TCP connections
  //WiFiClient client;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
  getTemp();
  Serial.println(temp);
  // We now create a URI for the request
  String url = "/update?key=";
  url += APIkey;
  url += "&field1=";
  url += String(temp);

  Serial.print("Requesting URL: ");
  Serial.println(url);
  Serial.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
               
  // 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");
  client.stop();
  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");
  //delay(26800);
  delay(2680);
}