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. 56
      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
arduino --install-boards esp32:esp32;
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; }
install:
- 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.
This example is for explaining how to use the AutoConnect library.
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 details, please refer to the project page.
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.
Copyright (c) 2018 Hieromon Ikasamo.
This software is released under the MIT License.
https://opensource.org/licenses/MIT
ESP8266/ESP32 publish the RSSI as the WiFi signal strength to ThingSpeak channel.
This example is for explaining how to use the AutoConnect library.
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 details, please refer to the project page.
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.
Copyright (c) 2018 Hieromon Ikasamo.
This software is released under the MIT License.
https://opensource.org/licenses/MIT
*/
#if defined(ARDUINO_ARCH_ESP8266)
@ -57,26 +57,22 @@ static const char AUX_mqtt_setting[] PROGMEM = R"raw(
{
"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"
},
{
@ -85,8 +81,7 @@ static const char AUX_mqtt_setting[] PROGMEM = R"raw(
"label": "Update period",
"value": [
"30 sec.",
"60 sec.",
"180 sec."
"60 sec."
],
"arrange": "vertical",
"checked": 1
@ -112,7 +107,7 @@ static const char AUX_mqtt_setting[] PROGMEM = R"raw(
{
"name": "save",
"type": "ACSubmit",
"value": "Save&Start",
"value": "Save&Start",
"uri": "/mqtt_save"
},
{
@ -166,8 +161,8 @@ unsigned long lastPub = 0;
bool mqttConnect() {
static const char alphanum[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"; // For random generation of client ID.
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"; // For random generation of client ID.
char clientId[9];
uint8_t retry = 10;
@ -186,7 +181,8 @@ bool mqttConnect() {
if (mqttClient.connect(clientId, MQTT_USER_ID, userKey.c_str())) {
Serial.println("Established:" + String(clientId));
return true;
} else {
}
else {
Serial.println("Connection failed:" + String(mqttClient.state()));
if (!--retry)
break;
@ -227,7 +223,10 @@ String loadParams(AutoConnectAux& aux, PageArgument& args) {
SPIFFS.begin();
File param = SPIFFS.open(PARAM_FILE, "r");
if (param) {
aux.loadElement(param);
// if (aux.loadElement(param))
// Serial.println(PARAM_FILE " loaded");
// else
// Serial.println(PARAM_FILE " failed to load");
param.close();
}
else
@ -249,13 +248,13 @@ String saveParams(AutoConnectAux& aux, PageArgument& args) {
channelId = args.arg("channelid");
channelId.trim();
userKey = args.arg("userkey");
userKey.trim();
apiKey = args.arg("apikey");
apiKey.trim();
String upd = args.arg("period");
updateInterval = upd.substring(0, 2).toInt() * 1000;
@ -263,7 +262,7 @@ String saveParams(AutoConnectAux& aux, PageArgument& args) {
hostName = args.arg("hostname");
hostName.trim();
// The entered value is owned by AutoConnectAux of /mqtt_setting.
// In order to retrieve the elements of /mqtt_setting,
// it is necessary to get the AutoConnectAux object of /mqtt_setting.
@ -360,7 +359,8 @@ void setup() {
if (portal.begin()) {
Serial.println("connected:" + WiFi.SSID());
Serial.println("IP:" + WiFi.localIP().toString());
} else {
}
else {
Serial.println("connection failed:" + String(WiFi.status()));
while (1) {
delay(100);

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

@ -120,13 +120,23 @@ class AutoConnectInputBasis : virtual public AutoConnectElementBasis {
*/
class AutoConnectRadioBasis : virtual public AutoConnectElementBasis {
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;
// _values = values;
// for (String v : values) {
// add(v);
// const std::string sv = v.c_str();
// _values.push_back(sv);
// }
}
virtual ~AutoConnectRadioBasis() {}
const String toHTML(void) const override;
void add(const String value) { _values.push_back(value); }
void empty(void) { _values.clear(); }
void add(const String& value) { _values.push_back(value); }
//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);
String label; /**< A label for a subsequent radio buttons */
@ -135,6 +145,7 @@ class AutoConnectRadioBasis : virtual public AutoConnectElementBasis {
protected:
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 {
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;
}
virtual ~AutoConnectSelectBasis() {}
const String toHTML(void) const override;
void add(const String option) { _options.push_back(option); }
void empty(void) { _options.clear(); }
void add(const String& option) { _options.push_back(option); }
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 */

@ -77,7 +77,8 @@ const String AutoConnectRadioBasis::toHTML(void) const {
html += String("<br>");
}
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("\"");
if (n == checked - 1)
html += String(FPSTR(" checked"));
@ -94,7 +95,8 @@ const String AutoConnectRadioBasis::toHTML(void) const {
*/
void AutoConnectRadioBasis::check(const String& value) {
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)) {
checked = n + 1;
break;

@ -143,6 +143,9 @@ class AutoConnectRadioJson : public AutoConnectElementJson, public AutoConnectRa
AutoConnectRadioBasis::label = label;
AutoConnectRadioBasis::order = order;
AutoConnectRadioBasis::checked = checked;
//for (String v : values) {
// AutoConnectRadioBasis::add(v);
//}
}
~AutoConnectRadioJson() {}
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_LABEL), label);
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)
values.add(v);
switch (order) {

Loading…
Cancel
Save