Created
February 6, 2021 02:27
-
-
Save kylejohnson/acaf92e175ffee275ab3a4b42d8b2111 to your computer and use it in GitHub Desktop.
Sending data to influxdb over UDP on an arduino
This file contains hidden or 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 <ESP8266WiFi.h> | |
#include <WiFiUdp.h> | |
const char ssid[] = "fubaz"; | |
const char pass[] = "fubar"; | |
WiFiUDP udp; | |
void setup(){ | |
Serial.begin(115200); | |
WiFi.begin(ssid, pass); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(); | |
} | |
void send_to_influxdb(byte bheartrate, byte bconfidence, byte boxygen, byte bsts){ | |
char heartrate[4]; | |
itoa(bheartrate, heartrate, 10); | |
char confidence[4]; | |
itoa(bconfidence, confidence, 10); | |
char oxygen[4]; | |
itoa(boxygen, oxygen, 10); | |
char sts[2]; | |
itoa(bsts, sts, 10); | |
Serial.println("Sending Bio data to InfluxDB."); | |
char line[64]; | |
sprintf(line, "bpm,confidence=%s,status=%d heartrate=%di,oxygen=%di", confidence, bsts, bheartrate, boxygen); | |
Serial.println(line); | |
udp.beginPacket("192.168.1.158", 8089); | |
udp.write(line); | |
udp.endPacket(); | |
} | |
void loop(){ | |
// Gather data | |
// Do stuff | |
send_to_influxdb(bheartrate, bconfidence, boxygen, bsts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment