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 23:47] mihai.volmer |
proiecte:influxdb [2017/02/16 00:46] (current) mihai.volmer [ESP8266] |
||
---|---|---|---|
Line 23: | Line 23: | ||
==== Configuration and deployment ==== | ==== Configuration and deployment ==== | ||
Deploying an InfluxDB is very straight forward. The [[https:// | 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 | InfluxDB is highly configurable. This is a great feature because it makes it flexible for a wide range | ||
Line 57: | Line 63: | ||
We assume the server is locally hosted, the database is called " | 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 | # To list every entry from the cpu series | ||
curl -G ' | curl -G ' | ||
Line 66: | Line 76: | ||
</ | </ | ||
+ | ===== ESP8266 ===== | ||
+ | ESP8266 is a very versatile device. It has a 80 MHz processor, 4MB of flash memory and WiFi connectivity, | ||
- | ===== ESP8266 ===== | + | 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 | ||
+ | // ..................... | ||
+ | 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 ===== | ===== 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. | 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. |