This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
proiecte:influxdb [2017/02/15 22:03] mihai.volmer |
proiecte:influxdb [2017/02/16 00:46] (current) mihai.volmer [ESP8266] |
||
---|---|---|---|
Line 13: | Line 13: | ||
===== InfluxDB ===== | ===== InfluxDB ===== | ||
+ | InfluxDB is a timeseries database with an SQL-like syntax. This means that the entries are indexed by a timestamp so they are easier to process. | ||
+ | |||
+ | Unlike other backend solutions, this provides only the database with HTTP and UDP endpoints that allow remote devices to insert or query data. | ||
+ | |||
+ | InfluxDB is free and open-source. This means that it can be deployed on any user-owned machine running Linux or Mac OSX. This is a great advantage because it provides greater flexibility. It can also run on multiple machines in a cluster-like infrastructure. | ||
+ | |||
+ | We have chosen InfluxDB in our project because we were able to deploy it on our machines and configure it how we wanted. Also, we were able to try different configurations without affecting other users. Another important reason is that the InfluxDB community is very active at this moment. | ||
+ | |||
+ | ==== Configuration and deployment ==== | ||
+ | Deploying an InfluxDB is very straight forward. The [[https:// | ||
+ | |||
+ | For Ubuntu 15.04+ or Debian 8+ systems: | ||
+ | < | ||
+ | sudo apt-get update && sudo apt-get install influxdb | ||
+ | sudo systemctl start influxdb | ||
+ | </ | ||
+ | |||
+ | InfluxDB is highly configurable. This is a great feature because it makes it flexible for a wide range | ||
+ | of usages. The configuration is made by modifying the / | ||
+ | |||
+ | We have temporarily disabled the Meta Service option since we did not use the server in a cluster-like infrastructure. We also enabled the Continuous query service. | ||
+ | |||
+ | For connectivity, | ||
+ | |||
+ | < | ||
+ | [http] | ||
+ | enabled = true | ||
+ | bind-address = ": | ||
+ | auth-enabled = true | ||
+ | log-enabled = true | ||
+ | write-tracing = false | ||
+ | pprof-enabled = false | ||
+ | https-enabled = false | ||
+ | https-certificate = "/ | ||
+ | |||
+ | [[udp]] | ||
+ | enabled = true | ||
+ | bind-address = ": | ||
+ | database = " | ||
+ | |||
+ | [continuous_queries] | ||
+ | log-enabled = true | ||
+ | enabled = true | ||
+ | </ | ||
+ | |||
+ | ==== Usage ===== | ||
+ | Here are some examples of commands used to insert and query data to/from the InfluxDB server. | ||
+ | |||
+ | We assume the server is locally hosted, the database is called " | ||
+ | |||
+ | The commands are written for bash. However, the queries can also be done manually (sending the whole query through a socket) or through a library. | ||
+ | |||
+ | < | ||
+ | # Insert an entry in the database with the tags host=' | ||
+ | curl -XPOST ' | ||
+ | |||
+ | # To list every entry from the cpu series | ||
+ | curl -G ' | ||
+ | |||
+ | # List mean values for each minute from the selected timeframe. Process only entries that have the tag host=' | ||
+ | curl -G ' | ||
+ | </ | ||
===== ESP8266 ===== | ===== ESP8266 ===== | ||
+ | ESP8266 is a very versatile device. It has a 80 MHz processor, 4MB of flash memory and WiFi connectivity, | ||
- | ===== Results ===== | + | It can use several firmwares, such as NodeMCU (lua interpreter) or micropython. However, these are slow and buggy. The device can also use Arduino firmware. This is preferable since there are many libraries already implemented. |
+ | To connect an ESP8266 to the WiFi as a station: | ||
+ | < | ||
+ | void setup() { | ||
+ | // Insert other code here, such as pin initializations | ||
+ | // ..................... | ||
- | ===== Resources ===== | + | const char* ssid = ""; |
+ | const char* password | ||
+ | // Connect tp Wifi | ||
+ | Serial.printf(" | ||
+ | WiFi.mode(WIFI_STA); | ||
+ | if (String(WiFi.SSID()) != String(ssid)) { | ||
+ | WiFi.begin(ssid, | ||
+ | } | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | Serial.println("" | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | Serial.println(WiFi.macAddress()); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | We made two implementations that send data from an LDR sensor to the server. | ||
+ | |||
+ | < | ||
+ | const int LDR = A0; | ||
+ | void loop() { | ||
+ | int ldr = analogRead(LDR); | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Sendint to HTTP endpoint (TCP) ==== | ||
+ | |||
+ | < | ||
+ | void setup() { | ||
+ | // Insert other code, such as wifi connection | ||
+ | // ................ | ||
+ | |||
+ | if (!client.connect(host, | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void send_value(int value) { | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Sendint to UDP endpoint ==== | ||
+ | |||
+ | InfluxDB has a very simple line protocol when using UDP. However, this has the disadvantage of sending the data in clear text. It also lets anyone who knows the server address to insert data without authentication. | ||
+ | |||
+ | < | ||
+ | void send_value(int ldr) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | ===== Results ===== | ||
+ | We have used a t2.micro (1 core of 2.4 GHz, 512MB RAM) AWS machine and a Lenovo Thinkpad W540 laptop (8 cores * 2.8GHz, 16GB RAM) to host our InfluxDB instances. | ||
+ | |||
+ | ===== Resources ===== | ||
+ | [[https:// | ||