Change function naming to be coherent across files

This commit is contained in:
Mathieu Maret 2016-03-24 14:54:55 +01:00
parent d729750ed5
commit a89a8a0727
5 changed files with 70 additions and 70 deletions

View File

@ -1,16 +1,16 @@
SFE_BMP180 bmp180; SFE_BMP180 bmp180;
int bmp180Connected = 0; int bmp180Connected = 0;
int setupBMP180() { int BMP180Setup() {
bmp180Connected = bmp180.begin(SDA, SCL); bmp180Connected = bmp180.begin(SDA, SCL);
return bmp180Connected; return bmp180Connected;
} }
bool isBMPConnected() { bool BMP180IsConnected() {
return bmp180Connected != 0; return bmp180Connected != 0;
} }
int getTemperature(double &t) { int BMP180GetTemperature(double &t) {
char status; char status;
status = bmp180.startTemperature(); status = bmp180.startTemperature();
if (status != 0) if (status != 0)
@ -24,8 +24,8 @@ int getTemperature(double &t) {
return -1; return -1;
} }
int getTempAndPressure(double &t, double &p) { int BMP180GetTempAndPressure(double &t, double &p) {
if (getTemperature(t) == 0) { if (BMP180GetTemperature(t) == 0) {
char status; char status;
status = bmp180.startPressure(3); status = bmp180.startPressure(3);
if (status != 0) if (status != 0)

View File

@ -5,7 +5,7 @@
*/ */
int saveConfig(uint8_t bootMode, String ssid, String password, String host, String mqttServer, String mqttUser, String mqttPasswd, int mqttPort) { int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host, String mqttServer, String mqttUser, String mqttPasswd, int mqttPort) {
String eeprom; String eeprom;
eeprom = String(bootMode) + ";" + ssid + ";" + password + ";" + host + ";" + mqttServer + ";" + mqttUser + ";" + mqttPasswd + ";" + String(mqttPort) + ";"; eeprom = String(bootMode) + ";" + ssid + ";" + password + ";" + host + ";" + mqttServer + ";" + mqttUser + ";" + mqttPasswd + ";" + String(mqttPort) + ";";
@ -25,7 +25,7 @@ int saveConfig(uint8_t bootMode, String ssid, String password, String host, Stri
return 0; return 0;
} }
int saveBootMode(uint8_t bootMode) { int EepromSaveBootMode(uint8_t bootMode) {
EEPROM.write(0, String(bootMode).charAt(0)); EEPROM.write(0, String(bootMode).charAt(0));
EEPROM.commit(); EEPROM.commit();
delay(100); delay(100);
@ -45,7 +45,7 @@ void readConfElement(char** element, int &i) {
} }
void readEEPROM(uint8_t &bootMode, char **ssid, char **password, char **host, char **mqttServer, char **mqttUser, char **mqttPasswd, int &mqttPort) { void EepromReadConfig(uint8_t &bootMode, char **ssid, char **password, char **host, char **mqttServer, char **mqttUser, char **mqttPasswd, int &mqttPort) {
int i = 2; int i = 2;

View File

@ -19,7 +19,7 @@ const char *GPIO_SET_FEED[] = { GPIO_BASE"12/set", GPIO_BASE"13/set"};
Adafruit_MQTT_Publish * mqttGpio[MAXSUBSCRIPTIONS] = {}; Adafruit_MQTT_Publish * mqttGpio[MAXSUBSCRIPTIONS] = {};
int setupMQTT(char *server, char *user, char *passwd, int port) { int MqttSetup(char *server, char *user, char *passwd, int port) {
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
mqtt = new Adafruit_MQTT_Client(&client, server, port, user, passwd); mqtt = new Adafruit_MQTT_Client(&client, server, port, user, passwd);
mqtt_temp = new Adafruit_MQTT_Publish(mqtt, TEMPERATURE_FEED); mqtt_temp = new Adafruit_MQTT_Publish(mqtt, TEMPERATURE_FEED);
@ -34,13 +34,13 @@ int setupMQTT(char *server, char *user, char *passwd, int port) {
return 0; return 0;
} }
int MQTT_isConnected() { int MqttIsConnected() {
return mqtt->connected(); return mqtt->connected();
} }
// Function to connect and reconnect as necessary to the MQTT server. // Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting. // Should be called in the loop function and it will take care if connecting.
int MQTT_connect() { int MqttConnect() {
int8_t ret; int8_t ret;
// Stop if already connected. // Stop if already connected.
@ -62,8 +62,8 @@ int MQTT_connect() {
return 0; return 0;
} }
int publishMQTT(double temp, double pressure) { int MqttPublish(double temp, double pressure) {
if (MQTT_connect() == 0) { if (MqttConnect() == 0) {
Serial.println("publishing !"); Serial.println("publishing !");
mqtt_temp->publish(temp); mqtt_temp->publish(temp);
mqtt_pressure->publish(pressure); mqtt_pressure->publish(pressure);
@ -92,7 +92,7 @@ int getGpioWatchedIndex(int gpio) {
return -1; return -1;
} }
void changeGpioValue(int gpio, int value) { void MqttChangeGpioValue(int gpio, int value) {
pinMode(gpio, OUTPUT); pinMode(gpio, OUTPUT);
digitalWrite(gpio, value); digitalWrite(gpio, value);
int watchIdx = getGpioWatchedIndex(gpio); int watchIdx = getGpioWatchedIndex(gpio);
@ -101,8 +101,8 @@ void changeGpioValue(int gpio, int value) {
} }
} }
void checkMqttSubscription() { void MqttCheckSubscription() {
if (MQTT_connect() == 0) { if (MqttConnect() == 0) {
Adafruit_MQTT_Subscribe *subscription; Adafruit_MQTT_Subscribe *subscription;
while (subscription = mqtt->readSubscription(0)) { while (subscription = mqtt->readSubscription(0)) {
int gpio = getGpioFromSubscription(subscription); int gpio = getGpioFromSubscription(subscription);
@ -112,7 +112,7 @@ void checkMqttSubscription() {
char *value = (char *) subscription->lastread; char *value = (char *) subscription->lastread;
Serial.print("Receive data: "); Serial.print("Receive data: ");
Serial.println(value); Serial.println(value);
changeGpioValue(gpio, atoi(value)); MqttChangeGpioValue(gpio, atoi(value));
} }
} }
} }

View File

@ -1,11 +1,11 @@
void handleRoot() { void WebHandleRoot() {
server.send(200, "text/html", server.send(200, "text/html",
"<head><meta http-equiv=\"refresh\" content=\"" + String(SAMPLING_PERIODE_MS / 1000) + "\" ></head>" "<head><meta http-equiv=\"refresh\" content=\"" + String(SAMPLING_PERIODE_MS / 1000) + "\" ></head>"
"<h1>You are connected</h1><br/>" "<h1>You are connected</h1><br/>"
"Current temperature " + String(temp, 2) + "C<br/>" "Current temperature " + String(temp, 2) + "C<br/>"
"Current pressure " + String(pressure, 2) + "mB<br/>" "Current pressure " + String(pressure, 2) + "mB<br/>"
"MQTT Status: " + (MQTT_isConnected() ? "Connected" : "Disconnected") + "<br/>" "MQTT Status: " + (MqttIsConnected() ? "Connected" : "Disconnected") + "<br/>"
"BMP 180 (Temp+Pression) Status: " + (isBMPConnected() ? "Connected" : "Disconnected") + "<br/>" "BMP 180 (Temp+Pression) Status: " + (BMP180IsConnected() ? "Connected" : "Disconnected") + "<br/>"
"Free space: "+ ESP.getFreeSketchSpace() +"<br/>" "Free space: "+ ESP.getFreeSketchSpace() +"<br/>"
"Free heap: "+ ESP.getFreeHeap() +"<br/>" "Free heap: "+ ESP.getFreeHeap() +"<br/>"
"<a href=\"/setup\">Setup</a><br/>" "<a href=\"/setup\">Setup</a><br/>"
@ -15,7 +15,7 @@ void handleRoot() {
); );
} }
void handleSetup() { void WebHandleSetup() {
uint8_t mode; uint8_t mode;
char *confSsid = ""; char *confSsid = "";
char *confPassword = ""; char *confPassword = "";
@ -25,7 +25,7 @@ void handleSetup() {
char *mqttPasswd = ""; char *mqttPasswd = "";
int mqttPort = 1883; int mqttPort = 1883;
readEEPROM(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort); EepromReadConfig(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort);
server.send(200, "text/html", "<form action=\"/save\" method=\"get\">" server.send(200, "text/html", "<form action=\"/save\" method=\"get\">"
"<fieldset>" "<fieldset>"
@ -45,17 +45,17 @@ void handleSetup() {
"</form>"); "</form>");
} }
void handleGpio() { void WebHandleGpio() {
if (!server.hasArg("gpio") || !server.hasArg("value")) { if (!server.hasArg("gpio") || !server.hasArg("value")) {
server.send(500, "text/plain", "Bad arguments\r\n"); server.send(500, "text/plain", "Bad arguments\r\n");
return; return;
} }
changeGpioValue(server.arg("gpio").toInt(), server.arg("value").toInt()); MqttChangeGpioValue(server.arg("gpio").toInt(), server.arg("value").toInt());
server.send(200, "text/html", "<h1>GPIO" + server.arg("gpio") + " changed to " + server.arg("value") + "</h1>"); server.send(200, "text/html", "<h1>GPIO" + server.arg("gpio") + " changed to " + server.arg("value") + "</h1>");
} }
void handleSave() { void WebHandleSave() {
String password; String password;
String ssid; String ssid;
String hostName; String hostName;
@ -68,7 +68,7 @@ void handleSave() {
return; return;
} }
if (saveConfig(BOOTMODE_NORMAL, server.arg("ssid"), server.arg("password"), server.arg("host"), server.arg("mqttServer"), server.arg("mqttUser"), server.arg("mqttPasswd"), server.arg("mqttPort").toInt()) < 0) { if (EepromSaveConfig(BOOTMODE_NORMAL, server.arg("ssid"), server.arg("password"), server.arg("host"), server.arg("mqttServer"), server.arg("mqttUser"), server.arg("mqttPasswd"), server.arg("mqttPort").toInt()) < 0) {
server.send(500, "text/plain", "Cannot Save Credentials (Too long ?Contains \";\"?)\r\n"); server.send(500, "text/plain", "Cannot Save Credentials (Too long ?Contains \";\"?)\r\n");
return; return;
} }
@ -77,14 +77,14 @@ void handleSave() {
"<a href=\"/reboot\">Reboot</a><br/>"); "<a href=\"/reboot\">Reboot</a><br/>");
} }
void handleOTA() { void WebHandleOTA() {
Serial.println("Boot mode Set to OTA"); Serial.println("Boot mode Set to OTA");
saveBootMode(BOOTMODE_OTA); EepromSaveBootMode(BOOTMODE_OTA);
server.send(200, "text/html", "<h1>OTA Mode set</h1><br/>" server.send(200, "text/html", "<h1>OTA Mode set</h1><br/>"
"You can reboot now"); "You can reboot now");
} }
void handleNotFound() { void WebHandleNotFound() {
String message = "File Not Found\n\n"; String message = "File Not Found\n\n";
message += "URI: "; message += "URI: ";
message += server.uri(); message += server.uri();
@ -99,21 +99,21 @@ void handleNotFound() {
server.send(404, "text/plain", message); server.send(404, "text/plain", message);
} }
void handleReboot() { void WebHandleReboot() {
Serial.println("HTTP request to reboot"); Serial.println("HTTP request to reboot");
server.send(200, "text/html", "<h1>Device Reboot</h1><br/>"); server.send(200, "text/html", "<h1>Device Reboot</h1><br/>");
ESP.restart(); ESP.restart();
} }
void setupWebServer(int bootmode) { void WebSetupServer(int bootmode) {
server.on("/", handleRoot); server.on("/", WebHandleRoot);
server.on("/setup", handleSetup); server.on("/setup", WebHandleSetup);
server.on("/save", handleSave); server.on("/save", WebHandleSave);
server.on("/gpio", handleGpio); server.on("/gpio", WebHandleGpio);
server.on("/otamode", handleOTA); server.on("/otamode", WebHandleOTA);
server.on("/reboot", handleReboot); server.on("/reboot", WebHandleReboot);
server.onNotFound(handleNotFound); server.onNotFound(WebHandleNotFound);
server.begin(); server.begin();
Serial.println("HTTP server started"); Serial.println("HTTP server started");
} }

View File

@ -51,35 +51,35 @@ const char *ssid = "ESPConfigurator";
ESP8266WebServer server(80); ESP8266WebServer server(80);
/* WebServer decl*/ /* WebServer decl*/
void handleRoot(); void WebHandleRoot();
void handleSetup(); void WebHandleSetup();
void handleGpio(); void WebHandleGpio();
void handleSave(); void WebHandleSave();
void handleOTA(); void WebHandleOTA();
void handleNotFound(); void WebHandleNotFound();
void setupWebServer(int bootmode); void WebSetupServer(int bootmode);
/* EEPROM decl */ /* EEPROM decl */
int saveConfig(uint8_t bootMode, String ssid, String password, String host, String mqttServer, String mqttUser, String mqttpasswd, int mqttPort); int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host, String mqttServer, String mqttUser, String mqttpasswd, int mqttPort);
int saveBootMode(uint8_t bootMode); int EepromSaveBootMode(uint8_t bootMode);
void readEEPROM(uint8_t &bootMode, char **ssid, char **password, char **host, char **mqttServer, char **mqttUser, char **mqttPasswd, int &mqttPort); void EepromReadConfig(uint8_t &bootMode, char **ssid, char **password, char **host, char **mqttServer, char **mqttUser, char **mqttPasswd, int &mqttPort);
/* BMP180 decl */ /* BMP180 decl */
int getTemperature(double &t); int BMP180GetTemperature(double &t);
int getTempAndPressure(double &t, double &p); int BMP180GetTempAndPressure(double &t, double &p);
int setupBMP180(); int BMP180Setup();
bool isBMPConnected(); bool BMP180IsConnected();
/* MQTT decl */ /* MQTT decl */
int MQTT_connect(); int MqttConnect();
int MQTT_isConnected(); int MqttIsConnected();
int setupMQTT(char *server, char *user, char *passwd, int port); int MqttSetup(char *server, char *user, char *passwd, int port);
int publishMQTT(double temp, double pressure); int MqttPublish(double temp, double pressure);
void checkMqttSubscription(); void MqttCheckSubscription();
void changeGpioValue(int gpio, int value); void MqttChangeGpioValue(int gpio, int value);
void setupWifi(int bootmode, int forceSetup, char *confSsid, char *confPassword, char *confHost) { void WifiSetup(int bootmode, int forceSetup, char *confSsid, char *confPassword, char *confHost) {
IPAddress myIP; IPAddress myIP;
if (bootmode == BOOTMODE_SETUP || forceSetup) { if (bootmode == BOOTMODE_SETUP || forceSetup) {
Serial.println("Configuring access point..."); Serial.println("Configuring access point...");
@ -110,7 +110,7 @@ void setupWifi(int bootmode, int forceSetup, char *confSsid, char *confPassword,
Serial.println(myIP); Serial.println(myIP);
} }
void setupOTA() { void OTASetup() {
// Port defaults to 8266 // Port defaults to 8266
// ArduinoOTA.setPort(8266); // ArduinoOTA.setPort(8266);
@ -122,7 +122,7 @@ void setupOTA() {
//Disable OTA mode to avoid forever loop //Disable OTA mode to avoid forever loop
//Force BOOTMODE_SETUP in case eeprom layout have changed //Force BOOTMODE_SETUP in case eeprom layout have changed
saveBootMode(BOOTMODE_SETUP); EepromSaveBootMode(BOOTMODE_SETUP);
ArduinoOTA.onStart([]() { ArduinoOTA.onStart([]() {
Serial.println("Start"); Serial.println("Start");
@ -173,7 +173,7 @@ void setup() {
#endif #endif
EEPROM.begin(EEPROM_SIZE); EEPROM.begin(EEPROM_SIZE);
readEEPROM(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort); EepromReadConfig(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort);
if (mode == BOOTMODE_NORMAL || mode == BOOTMODE_OTA) { if (mode == BOOTMODE_NORMAL || mode == BOOTMODE_OTA) {
Serial.println("Configuration Found !:"); Serial.println("Configuration Found !:");
Serial.println(mode); Serial.println(mode);
@ -193,15 +193,15 @@ void setup() {
Serial.print(txStatus ? "No" : "Yes"); Serial.print(txStatus ? "No" : "Yes");
Serial.println(); Serial.println();
setupWifi(mode, txStatus == 0, confSsid, confPassword, confHost); WifiSetup(mode, txStatus == 0, confSsid, confPassword, confHost);
setupMQTT(mqttServer, mqttUser, mqttPasswd, mqttPort); MqttSetup(mqttServer, mqttUser, mqttPasswd, mqttPort);
if (mode == BOOTMODE_OTA) { if (mode == BOOTMODE_OTA) {
setupOTA(); OTASetup();
} else { } else {
if (setupBMP180()) if (BMP180Setup())
Serial.println("BMP180 init success"); Serial.println("BMP180 init success");
setupWebServer(mode); WebSetupServer(mode);
} }
} }
@ -211,17 +211,17 @@ void loop() {
ArduinoOTA.handle(); ArduinoOTA.handle();
} else { } else {
server.handleClient(); server.handleClient();
checkMqttSubscription(); MqttCheckSubscription();
delay(WEB_DELAY_MS); delay(WEB_DELAY_MS);
nbCycle++; nbCycle++;
if (nbCycle > SAMPLING_PERIODE_MS / WEB_DELAY_MS) { if (nbCycle > SAMPLING_PERIODE_MS / WEB_DELAY_MS) {
if (isBMPConnected() && getTempAndPressure(temp, pressure) == 0) { if (BMP180IsConnected() && BMP180GetTempAndPressure(temp, pressure) == 0) {
Serial.print("Current T°C "); Serial.print("Current T°C ");
Serial.print(temp); Serial.print(temp);
Serial.print( " Pressure mB "); Serial.print( " Pressure mB ");
Serial.println(pressure); Serial.println(pressure);
publishMQTT(temp, pressure); MqttPublish(temp, pressure);
} else { } else {
Serial.println("Cannot get T°C"); Serial.println("Cannot get T°C");
} }