Something similar, but using the HTTP POST using the Arduino EthernetClient
if you're unable to modify the InfluxDB host config.
To use the code below: 1) Change the MAC address, 2) change the IP address
to your InfluxDB IP address, 3) change the line in the POST construction to
your InfluxDB and Port "client.println("Host: 192.168.1.136:8086");"
It starts breaking down when the loop delay is around 300ms. The POST is
coming from a microcontroller and going to a Raspberry Pi 3.
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the
shield
byte mac[] = { 0x00, 0x1A, 0xB6, 0x02, 0xF1, 0x16 };
IPAddress server(192, 168, 1, 136); // BBB
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
//data for HTTP Post;
String POSTData = "";
//data for HTTP response
char Response[255];
void setup()
{
//start Serial
Serial.begin(115200);
//initialize ethernet
if (Ethernet.begin(mac) == 0)
Serial.println("Failed to configure Ethernet");
// give the Ethernet peripheral a second to initialize:
delay(1000);
// let the monitor know it's starting
Serial.println("Starting");
}
void loop()
{
// connect to the influxdb port
if (!client.connect(server, 8086))
Serial.println("Did not connect");
// set some test data
String POSTData = "uCont value=" + String(millis());
// Make a HTTP request:
client.println("POST /write?db=mydb HTTP/1.1");
client.println("Host: 192.168.1.136:8086");
client.println("User-Agent: Arduino/1.6");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded;");
client.print("Content-Length: ");
client.println(POSTData.length());
client.println();
client.println(POSTData);
delay(30);
if (client.available())
{
client.readBytes(Response, client.available());
Serial.println(Response);
}
delay(1000);
// let the monitor know something is going on in case nothing is returned.
Serial.println("loop...");
}
--
Remember to include the version number!
---
You received this message because you are subscribed to the Google Groups
"InfluxData" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/influxdb.
To view this discussion on the web visit
https://groups.google.com/d/msgid/influxdb/80a1b13b-1b28-40ab-a663-7b6981ab5c8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.