Having a std::vector problem.

pull/41/head
Hieromon Ikasamo 6 years ago
parent 34e72ed255
commit ea7cb298ae
  1. 2
      .travis.yml
  2. 27
      examples/mqttRSSI/data/param.json
  3. 48
      examples/mqttRSSI/mqttRSSI.ino
  4. 2
      library.json
  5. 23
      src/AutoConnectElementBasis.h
  6. 6
      src/AutoConnectElementBasisImpl.h
  7. 3
      src/AutoConnectElementJson.h
  8. 4
      src/AutoConnectElementJsonImpl.h

@ -20,7 +20,7 @@ before_install:
- if [[ "$BOARD" =~ "esp32:esp32:" ]]; then - if [[ "$BOARD" =~ "esp32:esp32:" ]]; then
arduino --install-boards esp32:esp32; arduino --install-boards esp32:esp32;
fi fi
- arduino --install-library PubSubClient,ArduinoJson:5.13.3,PageBuilder:1.2.1 - arduino --install-library PubSubClient,ArduinoJson:5.13.3,PageBuilder:1.2.2
- buildExampleSketch() { arduino --verbose-build --verify --board $BOARD $PWD/examples/$1/$1.ino; } - buildExampleSketch() { arduino --verbose-build --verify --board $BOARD $PWD/examples/$1/$1.ino; }
install: install:
- mkdir -p ~/Arduino/libraries - mkdir -p ~/Arduino/libraries

@ -0,0 +1,27 @@
[
{
"name": "mqttserver",
"type": "ACInput",
"value": "mqtt.thingspeak.com",
"placeholder": "MQTT broker server",
"label": "Server"
},
{
"name": "channelid",
"type": "ACInput",
"value": "454951",
"label": "Channel ID"
},
{
"name": "userkey",
"type": "ACInput",
"value": "NRTFYGJ6TJFGX4RC",
"label": "User Key"
},
{
"name": "apikey",
"type": "ACInput",
"value": "HBVQ2XV6VYBI4582",
"label": "API Key"
}
]

@ -1,16 +1,16 @@
/* /*
ESP8266/ESP32 publish the RSSI as the WiFi signal strength to ThingSpeak channel. ESP8266/ESP32 publish the RSSI as the WiFi signal strength to ThingSpeak channel.
This example is for explaining how to use the AutoConnect library. This example is for explaining how to use the AutoConnect library.
In order to execute this example, the ThingSpeak account is needed. Sing up In order to execute this example, the ThingSpeak account is needed. Sing up
for New User Account and create a New Channel via My Channels. for New User Account and create a New Channel via My Channels.
For details, please refer to the project page. For details, please refer to the project page.
https://hieromon.github.io/AutoConnect/examples/index.html#used-with-mqtt-as-a-client-application https://hieromon.github.io/AutoConnect/examples/index.html#used-with-mqtt-as-a-client-application
This example is based on the environment as of March 20, 2018. This example is based on the environment as of March 20, 2018.
Copyright (c) 2018 Hieromon Ikasamo. Copyright (c) 2018 Hieromon Ikasamo.
This software is released under the MIT License. This software is released under the MIT License.
https://opensource.org/licenses/MIT https://opensource.org/licenses/MIT
*/ */
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
@ -57,26 +57,22 @@ static const char AUX_mqtt_setting[] PROGMEM = R"raw(
{ {
"name": "mqttserver", "name": "mqttserver",
"type": "ACInput", "type": "ACInput",
"value": "mqtt.thingspeak.com",
"placeholder": "MQTT broker server", "placeholder": "MQTT broker server",
"label": "Server" "label": "Server"
}, },
{ {
"name": "channelid", "name": "channelid",
"type": "ACInput", "type": "ACInput",
"value": "454951",
"label": "Channel ID" "label": "Channel ID"
}, },
{ {
"name": "userkey", "name": "userkey",
"type": "ACInput", "type": "ACInput",
"value": "NRTFYGJ6TJFGX4RC",
"label": "User Key" "label": "User Key"
}, },
{ {
"name": "apikey", "name": "apikey",
"type": "ACInput", "type": "ACInput",
"value": "HBVQ2XV6VYBI4582",
"label": "API Key" "label": "API Key"
}, },
{ {
@ -85,8 +81,7 @@ static const char AUX_mqtt_setting[] PROGMEM = R"raw(
"label": "Update period", "label": "Update period",
"value": [ "value": [
"30 sec.", "30 sec.",
"60 sec.", "60 sec."
"180 sec."
], ],
"arrange": "vertical", "arrange": "vertical",
"checked": 1 "checked": 1
@ -112,7 +107,7 @@ static const char AUX_mqtt_setting[] PROGMEM = R"raw(
{ {
"name": "save", "name": "save",
"type": "ACSubmit", "type": "ACSubmit",
"value": "Save&Start", "value": "Save&Start",
"uri": "/mqtt_save" "uri": "/mqtt_save"
}, },
{ {
@ -166,8 +161,8 @@ unsigned long lastPub = 0;
bool mqttConnect() { bool mqttConnect() {
static const char alphanum[] = "0123456789" static const char alphanum[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"; // For random generation of client ID. "abcdefghijklmnopqrstuvwxyz"; // For random generation of client ID.
char clientId[9]; char clientId[9];
uint8_t retry = 10; uint8_t retry = 10;
@ -186,7 +181,8 @@ bool mqttConnect() {
if (mqttClient.connect(clientId, MQTT_USER_ID, userKey.c_str())) { if (mqttClient.connect(clientId, MQTT_USER_ID, userKey.c_str())) {
Serial.println("Established:" + String(clientId)); Serial.println("Established:" + String(clientId));
return true; return true;
} else { }
else {
Serial.println("Connection failed:" + String(mqttClient.state())); Serial.println("Connection failed:" + String(mqttClient.state()));
if (!--retry) if (!--retry)
break; break;
@ -227,7 +223,10 @@ String loadParams(AutoConnectAux& aux, PageArgument& args) {
SPIFFS.begin(); SPIFFS.begin();
File param = SPIFFS.open(PARAM_FILE, "r"); File param = SPIFFS.open(PARAM_FILE, "r");
if (param) { if (param) {
aux.loadElement(param); // if (aux.loadElement(param))
// Serial.println(PARAM_FILE " loaded");
// else
// Serial.println(PARAM_FILE " failed to load");
param.close(); param.close();
} }
else else
@ -360,7 +359,8 @@ void setup() {
if (portal.begin()) { if (portal.begin()) {
Serial.println("connected:" + WiFi.SSID()); Serial.println("connected:" + WiFi.SSID());
Serial.println("IP:" + WiFi.localIP().toString()); Serial.println("IP:" + WiFi.localIP().toString());
} else { }
else {
Serial.println("connection failed:" + String(WiFi.status())); Serial.println("connection failed:" + String(WiFi.status()));
while (1) { while (1) {
delay(100); delay(100);

@ -12,7 +12,7 @@
[ [
{ {
"name": "PageBuilder", "name": "PageBuilder",
"version": ">=1.2.1" "version": ">=1.2.2"
} }
], ],
"frameworks": "arduino", "frameworks": "arduino",

@ -120,13 +120,23 @@ class AutoConnectInputBasis : virtual public AutoConnectElementBasis {
*/ */
class AutoConnectRadioBasis : virtual public AutoConnectElementBasis { class AutoConnectRadioBasis : virtual public AutoConnectElementBasis {
public: public:
explicit AutoConnectRadioBasis(const char* name = "", std::vector<String> values = {}, const char* label = "", const ACArrange_t order = AC_Vertical, const uint8_t checked = 0) : AutoConnectElementBasis(name, ""), label(label), order(order), checked(checked), _values(values) { explicit AutoConnectRadioBasis(const char* name = "", std::vector<String> const& values = {}, const char* label = "", const ACArrange_t order = AC_Vertical, const uint8_t checked = 0) : AutoConnectElementBasis(name, ""), label(label), order(order), checked(checked), _values(values) {
_type = AC_Radio; _type = AC_Radio;
// _values = values;
// for (String v : values) {
// add(v);
// const std::string sv = v.c_str();
// _values.push_back(sv);
// }
} }
virtual ~AutoConnectRadioBasis() {} virtual ~AutoConnectRadioBasis() {}
const String toHTML(void) const override; const String toHTML(void) const override;
void add(const String value) { _values.push_back(value); } void add(const String& value) { _values.push_back(value); }
void empty(void) { _values.clear(); } //void add(const String& value) {
// std::string sv = value.c_str();
// _values.push_back(sv);
//}
void empty(const size_t reserve = 0) { _values.reserve(reserve); _values.clear(); std::vector<String>().swap(_values); }
void check(const String& value); void check(const String& value);
String label; /**< A label for a subsequent radio buttons */ String label; /**< A label for a subsequent radio buttons */
@ -135,6 +145,7 @@ class AutoConnectRadioBasis : virtual public AutoConnectElementBasis {
protected: protected:
std::vector<String> _values; /**< Items in a group */ std::vector<String> _values; /**< Items in a group */
// std::vector<std::string> _values; /**< Items in a group */
}; };
/** /**
@ -147,13 +158,13 @@ class AutoConnectRadioBasis : virtual public AutoConnectElementBasis {
*/ */
class AutoConnectSelectBasis : virtual public AutoConnectElementBasis { class AutoConnectSelectBasis : virtual public AutoConnectElementBasis {
public: public:
explicit AutoConnectSelectBasis(const char* name = "", std::vector<String> options = {}, const char* label = "") : AutoConnectElementBasis(name, ""), label(String(label)), _options(options) { explicit AutoConnectSelectBasis(const char* name = "", std::vector<String> const& options = {}, const char* label = "") : AutoConnectElementBasis(name, ""), label(String(label)), _options(options) {
_type = AC_Select; _type = AC_Select;
} }
virtual ~AutoConnectSelectBasis() {} virtual ~AutoConnectSelectBasis() {}
const String toHTML(void) const override; const String toHTML(void) const override;
void add(const String option) { _options.push_back(option); } void add(const String& option) { _options.push_back(option); }
void empty(void) { _options.clear(); } void empty(const size_t reserve = 0) { _options.reserve(reserve); _options.clear(); std::vector<String>().swap(_options); }
String label; /**< A label for a subsequent input box */ String label; /**< A label for a subsequent input box */

@ -77,7 +77,8 @@ const String AutoConnectRadioBasis::toHTML(void) const {
html += String("<br>"); html += String("<br>");
} }
for (std::size_t n = 0; n < _values.size(); n++) { for (std::size_t n = 0; n < _values.size(); n++) {
String value = _values[n]; // String value = _values[n];
String value = String(_values[n].c_str());
html += String(FPSTR("<input type=\"radio\" name=\"")) + name + String(FPSTR("\" id=\"")) + value + String(FPSTR("\" value=\"")) + value + String("\""); html += String(FPSTR("<input type=\"radio\" name=\"")) + name + String(FPSTR("\" id=\"")) + value + String(FPSTR("\" value=\"")) + value + String("\"");
if (n == checked - 1) if (n == checked - 1)
html += String(FPSTR(" checked")); html += String(FPSTR(" checked"));
@ -94,7 +95,8 @@ const String AutoConnectRadioBasis::toHTML(void) const {
*/ */
void AutoConnectRadioBasis::check(const String& value) { void AutoConnectRadioBasis::check(const String& value) {
for (std::size_t n = 0; n < _values.size(); n++) { for (std::size_t n = 0; n < _values.size(); n++) {
String& v = _values[n]; // String& v = _values[n];
String v = String(_values[n].c_str());
if (v.equalsIgnoreCase(value)) { if (v.equalsIgnoreCase(value)) {
checked = n + 1; checked = n + 1;
break; break;

@ -143,6 +143,9 @@ class AutoConnectRadioJson : public AutoConnectElementJson, public AutoConnectRa
AutoConnectRadioBasis::label = label; AutoConnectRadioBasis::label = label;
AutoConnectRadioBasis::order = order; AutoConnectRadioBasis::order = order;
AutoConnectRadioBasis::checked = checked; AutoConnectRadioBasis::checked = checked;
//for (String v : values) {
// AutoConnectRadioBasis::add(v);
//}
} }
~AutoConnectRadioJson() {} ~AutoConnectRadioJson() {}
const size_t getObjectSize(void) const override; const size_t getObjectSize(void) const override;

@ -216,6 +216,10 @@ void AutoConnectRadioJson::serialize(JsonObject& json) {
json.set(F(AUTOCONNECT_JSON_KEY_TYPE), F(AUTOCONNECT_JSON_TYPE_ACRADIO)); json.set(F(AUTOCONNECT_JSON_KEY_TYPE), F(AUTOCONNECT_JSON_TYPE_ACRADIO));
json.set(F(AUTOCONNECT_JSON_KEY_LABEL), label); json.set(F(AUTOCONNECT_JSON_KEY_LABEL), label);
JsonArray& values = json.createNestedArray(F(AUTOCONNECT_JSON_KEY_VALUE)); JsonArray& values = json.createNestedArray(F(AUTOCONNECT_JSON_KEY_VALUE));
//for (std::string& v : _values) {
// String s = String(v.c_str());
// values.add(s);
//}
for (String v : _values) for (String v : _values)
values.add(v); values.add(v);
switch (order) { switch (order) {

Loading…
Cancel
Save