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 *ssid = "XXXXX";
|
||||||
const char *password = "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);
|
ADC_MODE(ADC_VCC);
|
||||||
void setup()
|
void setup()
|
||||||
@ -95,7 +97,7 @@ int mqttConnect(float h, float t)
|
|||||||
mqtt_temp = new Adafruit_MQTT_Publish(mqtt, TEMPERATURE_FEED_FORMAT, 0);
|
mqtt_temp = new Adafruit_MQTT_Publish(mqtt, TEMPERATURE_FEED_FORMAT, 0);
|
||||||
mqtt_pressure = new Adafruit_MQTT_Publish(mqtt, HUMIDITY_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);
|
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");
|
Serial.println("failed to send temp");
|
||||||
}
|
}
|
||||||
mqtt_pressure->publish(h);
|
mqtt_pressure->publish(h);
|
||||||
@ -135,11 +137,15 @@ int doMeasure()
|
|||||||
IPAddress gateway(192, 168, 0, 254);
|
IPAddress gateway(192, 168, 0, 254);
|
||||||
IPAddress subnet(255, 255, 255, 0);
|
IPAddress subnet(255, 255, 255, 0);
|
||||||
WiFi.config(ip, gateway, subnet);
|
WiFi.config(ip, gateway, subnet);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password, channel, bssid);
|
||||||
|
|
||||||
|
int retry = 10;
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(100);
|
delay(100);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
if (retry < 0)
|
||||||
|
continue;
|
||||||
|
retry --;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,7 +154,7 @@ int doMeasure()
|
|||||||
Serial.println("IP address: ");
|
Serial.println("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
mqttConnect(h, t);
|
mqttConnect(h, t);
|
||||||
if (WiFiOff()){
|
if (WiFiOff()) {
|
||||||
//if (WiFi.forceSleepBegin(0)) {
|
//if (WiFi.forceSleepBegin(0)) {
|
||||||
Serial.println("Fail to set sleep mode");
|
Serial.println("Fail to set sleep mode");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user