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/16 00:12] mihai.volmer [ESP8266] |
proiecte:influxdb [2017/02/16 00:46] (current) mihai.volmer [ESP8266] |
||
---|---|---|---|
Line 80: | Line 80: | ||
ESP8266 is a very versatile device. It has a 80 MHz processor, 4MB of flash memory and WiFi connectivity, | ESP8266 is a very versatile device. It has a 80 MHz processor, 4MB of flash memory and WiFi connectivity, | ||
- | 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. | + | 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. |