Last active
April 20, 2020 22:43
-
-
Save justind000/5ab1a872e8749eb657a9a567e32e026f to your computer and use it in GitHub Desktop.
uFire.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WiFiMulti.h> | |
#include <InfluxDbClient.h> // click to install: http://librarymanager/All#ESP8266-Influxdb | |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
#define WIFI_SSID "" // WiFi name | |
#define WIFI_PASSWORD "" // WiFi password | |
#define INFLUXDB_URL "" // The address of your instance, like 'https://awesome.ufire.net:9999' | |
#define INFLUXDB_ORG "" // Organization name. It can't have any spaces in it for this library. | |
#define INFLUXDB_BUCKET "" // Bucket name, // InfluxDB UI -> Load Data -> Buckets -> Make or select a bucket | |
#define DEVICE "" // The name of this device | |
#define INFLUXDB_TOKEN "" // InfluxDB UI -> Load Data -> Tokens -> Make or select a token | |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN); | |
WiFiMulti wifiMulti; | |
Point sensor("wifi_status"); // Data point | |
void setup() { | |
Serial.begin(115200); | |
// Setup wifi | |
WiFi.mode(WIFI_STA); | |
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD); | |
Serial.print("Connecting to WiFi"); | |
while (wifiMulti.run() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(100); | |
} | |
Serial.println(); | |
// Add tags | |
sensor.addTag("device", DEVICE); | |
sensor.addTag("SSID", WiFi.SSID()); | |
// Check server connection | |
if (client.validateConnection()) { | |
Serial.print("Connected to InfluxDB: "); | |
Serial.println(client.getServerUrl()); | |
} else { | |
Serial.print("InfluxDB connection failed: "); | |
Serial.println(client.getLastErrorMessage()); | |
} | |
} | |
void loop() { | |
sensor.clearFields(); // clear the fields to fill with new information | |
sensor.addField("rssi", WiFi.RSSI()); // Report RSSI of currently connected network | |
Serial.print((String)"Writing " + sensor.toLineProtocol()); // Print what what we're writing | |
// Write point | |
if (client.writePoint(sensor)) { | |
Serial.println(" OK"); | |
} else { | |
Serial.println(); | |
Serial.println((String)"InfluxDB write failed: " + client.getLastErrorMessage()); | |
} | |
delay(10000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment