Skip to content

Commit

Permalink
Merge pull request #1 from jomjol/rolling
Browse files Browse the repository at this point in the history
Rolling
  • Loading branch information
phlupp authored Sep 19, 2020
2 parents df80124 + bb05957 commit 6a047d1
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 34 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571



##### Rolling - (2020-09-13)
##### Rolling - (2020-09-16)

* Impovements in hostname

2020-09-14

* Implementation of hostname in wlan.ini (`hostname = "HOSTNAME")` - Parameter is optional

* Bug correction DecimalShift

2020-09-13

* Bug fixing DecimalShift (digits after comma)

Expand Down
29 changes: 24 additions & 5 deletions code/lib/connect_wlan/connect_wlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ static const char *MAIN_TAG = "connect_wlan";

std::string ssid;
std::string passphrase;
std::string hostname;

std::string std_hostname = "watermeter";

static EventGroupHandle_t wifi_event_group;

Expand Down Expand Up @@ -100,33 +103,36 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
return ESP_OK;
}

void initialise_wifi(std::string _ssid, std::string _passphrase)
void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _hostname)
{
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL) );
wifi_event_group = xEventGroupCreate();
ssid = _ssid;
passphrase = _passphrase;
hostname = _hostname;
esp_log_level_set("wifi", ESP_LOG_NONE); // disable wifi driver logging
tcpip_adapter_init();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_start() );
esp_err_t ret = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA ,"icircuit");
esp_err_t ret = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA , hostname.c_str());
if(ret != ESP_OK ){
ESP_LOGE(MAIN_TAG,"failed to set hostname:%d",ret);
}
xEventGroupWaitBits(wifi_event_group,CONNECTED_BIT,true,true,portMAX_DELAY);
tcpip_adapter_ip_info_t ip_info;
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
printf("IP : %s\n", ip4addr_ntoa(&ip_info.ip));
printf("IPv4 : %s\n", ip4addr_ntoa(&ip_info.ip));
printf("HostName : %s\n", hostname.c_str());
}


void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase)
void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase, std::string &_hostname)
{
string line = "";
std::vector<string> zerlegt;
_hostname = std_hostname;

FILE* pFile;
fn = FormatFileName(fn);
Expand All @@ -145,13 +151,26 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
// printf("%s", line.c_str());
zerlegt = ZerlegeZeile(line, "=");
zerlegt[0] = trim(zerlegt[0], " ");
zerlegt[1] = trim(zerlegt[1], " ");
zerlegt[1] = trim(zerlegt[1], " ");

if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){
_hostname = zerlegt[1];
if ((_hostname[0] == '"') && (_hostname[_hostname.length()-1] == '"')){
_hostname = _hostname.substr(1, _hostname.length()-2);
}
// Check if Hostname was empty in .ini if yes set to std_hostname
if(_hostname.length() <= 0){
_hostname = std_hostname;
}
}

if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "SSID")){
_ssid = zerlegt[1];
if ((_ssid[0] == '"') && (_ssid[_ssid.length()-1] == '"')){
_ssid = _ssid.substr(1, _ssid.length()-2);
}
}

if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "PASSWORD")){
_passphrase = zerlegt[1];
if ((_passphrase[0] == '"') && (_passphrase[_passphrase.length()-1] == '"')){
Expand Down
4 changes: 2 additions & 2 deletions code/lib/connect_wlan/connect_wlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

const int CONNECTED_BIT = BIT0;

void initialise_wifi(std::string _ssid, std::string _passphrase);
void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _hostname);

void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase);
void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase, std::string &_hostname);

#endif
2 changes: 1 addition & 1 deletion code/lib/jomjol_flowcontroll/ClassFlowControll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
if (flowpostprocessing)
{
flowpostprocessing->SavePreValue(zw);
return _newvalue;
return to_string(zw);
}

return std::string();
Expand Down
52 changes: 32 additions & 20 deletions code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ string ClassFlowPostProcessing::GetPreValue()
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
{
int AnzahlNachkomma = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
result = RundeOutput(PreValue, AnzahlNachkomma - DecimalShift);
int AnzahlAnalog = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
result = RundeOutput(PreValue, AnzahlAnalog - DecimalShift);
}
}

Expand Down Expand Up @@ -78,8 +78,8 @@ bool ClassFlowPostProcessing::LoadPreValue(void)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
{
int AnzahlNachkomma = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
ReturnValue = RundeOutput(Value, AnzahlNachkomma - DecimalShift);
int AnzahlAnalog = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
ReturnValue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
ReturnValueNoError = ReturnValue;
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
string zwvalue;
bool isdigit = false;
bool isanalog = false;
int AnzahlNachkomma = 0;
int AnzahlAnalog = 0;
string zw;
string error = "";
time_t imagetime = 0;
Expand All @@ -282,7 +282,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
{
isanalog = true;
analog = (*ListFlowControll)[i]->getReadout();
AnzahlNachkomma = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
AnzahlAnalog = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
}
}

Expand Down Expand Up @@ -329,6 +329,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
return true;
}

/*
if (isdigit)
{
int lastanalog = -1;
Expand All @@ -342,23 +343,27 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
zw = zw + ".";
if (isanalog)
zw = zw + analog;
zw = ShiftDecimal(zw, DecimalShift);
*/

zw = ErsetzteN(ReturnRawValue);

Value = std::stof(zw);
zwvalue = RundeOutput(Value, AnzahlNachkomma - DecimalShift);
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);

if ((!AllowNegativeRates) && (Value < PreValue))
{
error = "Negative Rate - Returned old value - read value: " + zwvalue;
Value = PreValue;
zwvalue = RundeOutput(Value, AnzahlNachkomma - DecimalShift);
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
}
else
{
if (useMaxRateValue && (abs(Value - PreValue) > MaxRateValue))
{
error = "Rate too high - Returned old value - read value: " + zwvalue;
Value = PreValue;
zwvalue = RundeOutput(Value, AnzahlNachkomma - DecimalShift);
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
}
}

Expand Down Expand Up @@ -394,32 +399,39 @@ string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
}


string ClassFlowPostProcessing::ErsetzteN(string input, int lastvalueanalog = -1)
string ClassFlowPostProcessing::ErsetzteN(string input)
{
int posN, posPunkt;
int pot, ziffer;
float zw;

posN = findDelimiterPos(input, "N");
posPunkt = input.length();
posPunkt = findDelimiterPos(input, ".");
if (posPunkt == std::string::npos){
posPunkt = input.length();
}

while (posN != std::string::npos)
{
pot = posPunkt - posN - 1;
if (posN < posPunkt) {
pot = posPunkt - posN - 1;
}
else {
pot = posPunkt - posN;
}

zw = PreValue / pow(10, pot);
ziffer = ((int) zw) % 10;
input[posN] = ziffer + 48;

posN = findDelimiterPos(input, "N");
}

///////////////////////////// TestCode
/*
input = "10";
posPunkt = input.length();
PreValue = 9.5;
lastvalueanalog = 7;
*/
return input;
}

string ClassFlowPostProcessing::checkDigitConsistency(string input, int _decilamshift, int lastvalueanalog){
/*
if (checkDigitIncreaseConsistency && lastvalueanalog > -1)
{
int zifferIST;
Expand Down Expand Up @@ -450,7 +462,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, int lastvalueanalog = -1
}

}
*/
return input;
}
3 changes: 2 additions & 1 deletion code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ClassFlowPostProcessing :
bool LoadPreValue(void);
string ShiftDecimal(string in, int _decShift);

string ErsetzteN(string, int lastvalueanalog);
string ErsetzteN(string);
string checkDigitConsistency(string, int _decilamshift, int lastvalueanalog = -1);
string RundeOutput(float _in, int _anzNachkomma);

public:
Expand Down
9 changes: 6 additions & 3 deletions code/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ extern "C" void app_main()
LogFile.WriteToFile("Startsequence 03");
std::string ssid = "";
std::string password = "";
LoadWlanFromFile("/sdcard/wlan.ini", ssid, password);
std::string hostname = "";

LoadWlanFromFile("/sdcard/wlan.ini", ssid, password, hostname);
LogFile.WriteToFile("Startsequence 04");
printf("WLan: %s, %s\n", ssid.c_str(), password.c_str());
printf("To use WLan: %s, %s\n", ssid.c_str(), password.c_str());
printf("To set Hostename: %s\n", hostname.c_str());

initialise_wifi(ssid, password);
initialise_wifi(ssid, password, hostname);
LogFile.WriteToFile("Startsequence 05");

TickType_t xDelay;
Expand Down
Binary file modified firmware/firmware.bin
Binary file not shown.
4 changes: 3 additions & 1 deletion sd-card/wlan.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ssid = "SSID"
password = "PASSWORD"
password = "PASSWORD"
hostname = "watermeter"
;hostname is optional

0 comments on commit 6a047d1

Please sign in to comment.