aboutsummaryrefslogtreecommitdiff
path: root/apps/sm-get-value.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-26 08:43:27 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-26 08:43:27 +0100
commit5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df (patch)
tree2fccb6a04bf62701a38617a22711f7dad23096a9 /apps/sm-get-value.cpp
parent4671571c93db7f083db21cfca526ac382cdfc7ad (diff)
downloadble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.tar.gz
ble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.tar.bz2
ble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.tar.xz
ble-toys-5a8fa2161ba5b53ab05e43649e8ae5532cf0a8df.zip
o Adding utility to insert samples from json files.
Diffstat (limited to 'apps/sm-get-value.cpp')
-rw-r--r--apps/sm-get-value.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/apps/sm-get-value.cpp b/apps/sm-get-value.cpp
index 97858f4..14a90de 100644
--- a/apps/sm-get-value.cpp
+++ b/apps/sm-get-value.cpp
@@ -18,7 +18,8 @@ using json = nlohmann::json;
enum class Format {
PLAIN,
- JSON
+ JSON,
+ SQL
};
void validate(boost::any &v, const std::vector<std::string> &values, Format *, int) {
@@ -26,10 +27,12 @@ void validate(boost::any &v, const std::vector<std::string> &values, Format *, i
const std::string &s = validators::get_single_string(values);
- if (s == "json") {
- v = boost::any(Format::JSON);
- } else if (s == "plain") {
+ if (s == "plain") {
v = boost::any(Format::PLAIN);
+ } else if (s == "json") {
+ v = boost::any(Format::JSON);
+ } else if (s == "sql") {
+ v = boost::any(Format::SQL);
} else {
throw validation_error(validation_error::invalid_option_value);
}
@@ -43,8 +46,10 @@ string lexical_cast(const Format &arg) {
return "plain";
else if (arg == Format::JSON)
return "json";
+ else if (arg == Format::SQL)
+ return "sql";
else
- throw std::runtime_error("Unknown Format value: " + to_string(static_cast<std::underlying_type<Format>::type>(arg)));
+ throw std::runtime_error("Unknown format value: " + lexical_cast<string>(arg));
}
}
@@ -98,6 +103,12 @@ void withConnection(BluetoothGatt &gatt) {
j["timestamp"] = timestamp;
j["value"] = value;
cout << j << endl;
+ } else if (format == Format::SQL) {
+ cout << "INSERT INTO soil_moisture_sample(device, sensor, timestamp, value) VALUES("
+ << "'" << device.str() << "', "
+ << sensor << ", "
+ << timestamp << ", "
+ << value << ";" << endl;
}
}