-->
Page 1 of 1

Set ESP8266 to station mode only?

PostPosted: Tue Dec 15, 2015 9:35 pm
by popngood
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);
}

Re: Set ESP8266 to station mode only?

PostPosted: Wed Dec 16, 2015 5:39 pm
by TBLD
You need to change the mode everytime you restart the board

So just add this line to your setup routine

WiFi.mode(WIFI_STA);

TBLD

Re: Set ESP8266 to station mode only?

PostPosted: Sun Dec 20, 2015 2:41 pm
by popngood
Great Thanks. That's the line I was looking for.