User Tools

Site Tools


proiecte:influxdb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
proiecte:influxdb [2017/02/15 23:51]
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://docs.influxdata.com/influxdb/v1.2/introduction/installation/ | official website]] has extensive documentation regarding deployment, configuration and usage. Deploying an InfluxDB is very straight forward. The [[https://docs.influxdata.com/influxdb/v1.2/introduction/installation/ | official website]] has extensive documentation regarding deployment, configuration and usage.
 +
 +For Ubuntu 15.04+ or Debian 8+ systems:
 +<code>
 +sudo apt-get update && sudo apt-get install influxdb
 +sudo systemctl start influxdb
 +</code>
  
 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 72: Line 78:
 ===== ESP8266 ===== ===== ESP8266 =====
  
 +ESP8266 is a very versatile device. It has a 80 MHz processor, 4MB of flash memory and WiFi connectivity, all in a finger-sized  device. It is also very cheap.
  
 +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:
 +<code>
 +void setup() {
 +  // Insert other code here, such as pin initializations
 +  // .....................
 +
 +  const char* ssid = "";
 +  const char* password = "";
 +
 +  // Connect tp Wifi
 +  Serial.printf("Connecting to %s\n", ssid);
 +  WiFi.mode(WIFI_STA);
 +  if (String(WiFi.SSID()) != String(ssid)) {
 +    WiFi.begin(ssid, password);
 +  }
 +  while (WiFi.status() != WL_CONNECTED) {
 +    delay(500);
 +    Serial.print(".");
 +  }
 +
 +  Serial.println("");
 +  Serial.print("Connected! IP address: ");
 +  Serial.println(WiFi.localIP());
 +
 +  Serial.print("IP address: ");
 +  Serial.println(WiFi.localIP());
 +  Serial.println(WiFi.macAddress());
 +}
 +</code>
 +
 +We made two implementations that send data from an LDR sensor to the server.
 +
 +<code>
 +const int LDR = A0;
 +void loop() {
 +   int ldr = analogRead(LDR);
 +   Serial.printf("LDR value = %d\n", ldr);
 +
 +   send_value(ldr);
 +
 +   delay(500);
 +}
 +</code>
 +
 +==== Sendint to HTTP endpoint (TCP) ====
 +
 +<code>
 +void setup() {
 +   // Insert other code, such as wifi connection
 +   // ................
 +
 +   if (!client.connect(host, port)) {
 +     Serial.println("connection failed");
 +     return;
 +   }
 +}
 +   
 +void send_value(int value) {
 +   String content = "cpu,host=esp8266 ldr=" + String(value);
 +   
 +   client.print("POST /write?db=mydb HTTP/1.1\r\n");
 +   client.print("User-Agent: esp8266/0.1\r\n");
 +   client.print("Host: localhost:8086\r\n");
 +   client.print("Accept: */*\r\n");
 +   client.print("Content-Length: " + String(content.length()) + "\r\n");
 +   client.print("Content-Type: application/x-www-form-urlencoded\r\n");
 +   client.print("\r\n");
 +   client.print(content + "\r\n");
 +
 +   client.flush();
 +}
 +</code>
 +
 +==== 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.
 +
 +<code>
 +void send_value(int ldr) {
 +   String content = "cpu,host=esp8266 ldr=" + String(ldr);
 +   udp.beginPacket(host, port);
 +   udp.print(content);
 +   udp.endPacket();
 +}
 +</code>
 ===== 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.
proiecte/influxdb.1487195493.txt.gz · Last modified: 2017/02/15 23:51 by mihai.volmer