Can use bssid and channel to save power
It's much faster to connect to wifi, so less power hungry
This commit is contained in:
parent
b19406af98
commit
27145540e1
@ -37,6 +37,8 @@ Adafruit_MQTT_Publish *mqtt_voltage;
|
||||
|
||||
const char *ssid = "XXXXX";
|
||||
const char *password = "XXXXX";
|
||||
uint8_t bssid[6] = {0x14, 0x0C, 0x76, 0xB1, 0x37, 0x32};
|
||||
int32_t channel = 11; //0 for Auto
|
||||
|
||||
ADC_MODE(ADC_VCC);
|
||||
void setup()
|
||||
@ -95,9 +97,9 @@ int mqttConnect(float h, float t)
|
||||
mqtt_temp = new Adafruit_MQTT_Publish(mqtt, TEMPERATURE_FEED_FORMAT, 0);
|
||||
mqtt_pressure = new Adafruit_MQTT_Publish(mqtt, HUMIDITY_FEED_FORMAT, 0);
|
||||
mqtt_voltage = new Adafruit_MQTT_Publish(mqtt, VOLTAGE_FEED_FORMAT, 0);
|
||||
if(!mqtt_temp->publish(t)){
|
||||
if (!mqtt_temp->publish(t)) {
|
||||
Serial.println("failed to send temp");
|
||||
}
|
||||
}
|
||||
mqtt_pressure->publish(h);
|
||||
mqtt_voltage->publish(ESP.getVcc());
|
||||
mqtt->disconnect();
|
||||
@ -135,11 +137,15 @@ int doMeasure()
|
||||
IPAddress gateway(192, 168, 0, 254);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
WiFi.config(ip, gateway, subnet);
|
||||
WiFi.begin(ssid, password);
|
||||
WiFi.begin(ssid, password, channel, bssid);
|
||||
|
||||
int retry = 10;
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(100);
|
||||
Serial.print(".");
|
||||
if (retry < 0)
|
||||
continue;
|
||||
retry --;
|
||||
}
|
||||
|
||||
|
||||
@ -148,8 +154,8 @@ int doMeasure()
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
mqttConnect(h, t);
|
||||
if (WiFiOff()){
|
||||
//if (WiFi.forceSleepBegin(0)) {
|
||||
if (WiFiOff()) {
|
||||
//if (WiFi.forceSleepBegin(0)) {
|
||||
Serial.println("Fail to set sleep mode");
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user