Skip to content

Instantly share code, notes, and snippets.

@kylejohnson
Created February 6, 2021 02:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylejohnson/acaf92e175ffee275ab3a4b42d8b2111 to your computer and use it in GitHub Desktop.
Save kylejohnson/acaf92e175ffee275ab3a4b42d8b2111 to your computer and use it in GitHub Desktop.
Sending data to influxdb over UDP on an arduino
#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