Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This sketch sends a temperature data from a BMP180 temp sensor to a raspberry pi running influxdb/grafana
- *
- */
- #include <ESP8266WiFi.h>
- #include <ESP8266WiFiMulti.h>
- #include <WiFiUdp.h>
- #include <SFE_BMP180.h>
- #include <Wire.h>
- ESP8266WiFiMulti WiFiMulti;
- SFE_BMP180 pressure;
- void setup() {
- Serial.begin(115200);
- delay(10);
- if (pressure.begin())
- Serial.println("BMP180 init success");
- else
- {
- Serial.println("BMP180 init fail. Check cables.\n\n");
- while(1); // Pause forever.
- }
- WiFiMulti.addAP("SSID****", "Password***");
- Serial.println();
- Serial.println();
- Serial.print("Wait for WiFi... ");
- while(WiFiMulti.run() != WL_CONNECTED) {
- Serial.print(".");
- delay(500);
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- delay(500);
- }
- void loop() {
- delay(5000);
- const uint16_t port = 8888;
- const char * host = "192.168.1.33"; // IP for influxdb
- char status;
- double T;
- Serial.print("connecting to ");
- Serial.println(host);
- // Use WiFiClient class to create TCP connections
- WiFiUDP udp;
- status = pressure.startTemperature();
- if (status != 0)
- {
- // Wait for the measurement to complete:
- delay(status);
- // Retrieve the completed temperature measurement:
- // Note that the measurement is stored in the variable T.
- // Function returns 1 if successful, 0 if failure.
- status = pressure.getTemperature(T);
- }
- String line;
- // Edit below line to set device ID
- line = String("temperature,device=downstairs value=" + String(T));
- udp.beginPacket(host,port);
- udp.print(line);
- udp.endPacket();
- Serial.println("closing connection");
- udp.stop();
- Serial.println("wait 8 min...");
- delay(500000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement