Skip to content

Commit

Permalink
Fix offset command, add offset to web gui, add dhcp hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
softypit committed Jan 17, 2020
1 parent e9d24b6 commit dd46d17
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
14 changes: 10 additions & 4 deletions main/eq3_bootwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,21 +904,27 @@ static void saveConnectionInfo(connection_info_t *pConnectionInfo) {
* Become a station connecting to an existing access point.
*/
static void becomeStation(connection_info_t *pConnectionInfo) {
ESP_LOGD(tag, "- Connecting to access point \"%s\" ...", pConnectionInfo->ssid);
ESP_LOGI(tag, "- Connecting to access point \"%s\" ...", pConnectionInfo->ssid);
assert(strlen(pConnectionInfo->ssid) > 0);

/* If this is a retry don't re-initialise sta mode */
if(sta_configured == false){
ESP_ERROR_CHECK(esp_wifi_stop());
// If we have a static IP address information, use that.
if (pConnectionInfo->ipInfo.ip.addr != 0) {
ESP_LOGD(tag, " - using a static IP address of " IPSTR, IP2STR(&pConnectionInfo->ipInfo.ip));
ESP_LOGI(tag, " - using a static IP address of " IPSTR, IP2STR(&pConnectionInfo->ipInfo.ip));
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &pConnectionInfo->ipInfo);
} else {
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
}

if(strlen(pConnectionInfo->mqttid) == 0){
tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, "EQ3-heatcontroller");
ESP_LOGI(tag, "Hostname EQ3-heatcontroller");
}else{
tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, pConnectionInfo->mqttid);
ESP_LOGI(tag, "Hostname %s", pConnectionInfo->mqttid);
}
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA));
wifi_config_t sta_config;
memset(&sta_config, 0, sizeof(wifi_config_t));
Expand All @@ -939,7 +945,7 @@ static void becomeStation(connection_info_t *pConnectionInfo) {
* Become an access point.
*/
static void becomeAccessPoint() {
ESP_LOGD(tag, "- Starting being an access point ...");
ESP_LOGI(tag, "- Starting being an access point ...");
// We don't have connection info so be an access point!
ESP_ERROR_CHECK(esp_wifi_stop());
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
Expand Down
3 changes: 3 additions & 0 deletions main/eq3_htmlpages.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ const char command_post_device[] = "</select></td><td><select name=\"command\">
<option value=\"auto\">auto</option> \
<option value=\"manual\">manual</option> \
<option value=\"settemp\">settemp</option> \
<option value=\"off\">closed (off)</option> \
<option value=\"on\">open (on)</option> \
<option value=\"offset\">offsettemp</option> \
<option value=\"settime\">settime</option> \
</select> \
</td><td><input type=\"text\" name=\"value\"></td></tr> \
Expand Down
24 changes: 12 additions & 12 deletions main/eq3_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ int handle_request(char *cmdstr){
// Skip any spaces
while(*cmdptr == ' ')
cmdptr++;
if(strncmp((const char *)cmdptr, "settime", 7) == 0){
if(start == false && strncmp((const char *)cmdptr, "settime", 7) == 0){
start = true;

if(cmdptr[8] != 0 && strlen(cmdptr + 8) < 12){
Expand Down Expand Up @@ -771,31 +771,31 @@ int handle_request(char *cmdstr){
}
command = EQ3_SETTIME;
}
if(strncmp((const char *)cmdptr, "boost", 5) == 0){
if(start == false && strncmp((const char *)cmdptr, "boost", 5) == 0){
start = true;
command = EQ3_BOOST;
}
if(strncmp((const char *)cmdptr, "unboost", 7) == 0){
if(start == false && strncmp((const char *)cmdptr, "unboost", 7) == 0){
start = true;
command = EQ3_UNBOOST;
}
if(strncmp((const char *)cmdptr, "auto", 4) == 0){
if(start == false && strncmp((const char *)cmdptr, "auto", 4) == 0){
start = true;
command = EQ3_AUTO;
}
if(strncmp((const char *)cmdptr, "manual", 6) == 0){
if(start == false && strncmp((const char *)cmdptr, "manual", 6) == 0){
start = true;
command = EQ3_MANUAL;
}
if(strncmp((const char *)cmdptr, "lock", 4) == 0){
if(start == false && strncmp((const char *)cmdptr, "lock", 4) == 0){
start = true;
command = EQ3_LOCK;
}
if(strncmp((const char *)cmdptr, "unlock", 6) == 0){
if(start == false && strncmp((const char *)cmdptr, "unlock", 6) == 0){
start = true;
command = EQ3_UNLOCK;
}
if(strncmp((const char *)cmdptr, "offset", 6) == 0){
if(start == false && strncmp((const char *)cmdptr, "offset", 6) == 0){
char *endmsg;
float offset = strtof(cmdptr + 7, &endmsg);
if(offset < -3.5 || offset > 3.5){
Expand All @@ -810,7 +810,7 @@ int handle_request(char *cmdstr){
command = EQ3_OFFSET;
ESP_LOGI(GATTC_TAG, "set offset val 0x%x\n", cmdparms[0]);
}
if(strncmp((const char *)cmdptr, "settemp", 7) == 0){
if(start == false && strncmp((const char *)cmdptr, "settemp", 7) == 0){
char *endmsg;
float temp = strtof(cmdptr + 8, &endmsg);
int inttemp = (int)temp;
Expand All @@ -826,13 +826,13 @@ int handle_request(char *cmdstr){
return -1;
}
}
if(strncmp((const char *)cmdptr, "off", 3) == 0){
if(start == false && strncmp((const char *)cmdptr, "off", 3) == 0){
/* 'Off' is achieved by setting the required temperature to 4.5 */
start = true;
command = EQ3_SETTEMP;
cmdparms[0] = 0x09; /* (4 << 1) | 0x01 */
}
if(strncmp((const char *)cmdptr, "on", 2) == 0){
if(start == false && strncmp((const char *)cmdptr, "on", 2) == 0){
/* 'On' is achieved by setting the required temperature to 30 */
start = true;
command = EQ3_SETTEMP;
Expand Down Expand Up @@ -1120,7 +1120,7 @@ void wifidone(int rc){
time_t now = 0;
struct tm timeinfo = { 0 };
int retry = 0;
const int retry_count = 10;
const int retry_count = 30;
while(timeinfo.tm_year < (2019 - 1900) && ++retry < retry_count) {
ESP_LOGI(GATTC_TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
vTaskDelay(2000 / portTICK_PERIOD_MS);
Expand Down
2 changes: 1 addition & 1 deletion main/eq3_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define EQ3_MAIN_H

#define EQ3_MAJVER "1"
#define EQ3_MINVER "49"
#define EQ3_MINVER "51"
#define EQ3_EXTRAVER "-beta"

void eq3_log_init(void);
Expand Down

0 comments on commit dd46d17

Please sign in to comment.