Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add influx 1 example #15

Closed
wants to merge 2 commits into from
Closed

Conversation

hez
Copy link

@hez hez commented Nov 3, 2021

This is similar to examples/C02_PM_SHT_OLED_WIFI but it pushes to an InfluxDB instead of Prometheus. Thought it might be helpful for others out there!

I made a few quality of life improvements line 40-41: defined the refresh rate for screen and push (don't want to push every 3seconds to the db).

Cheers

@danepowell
Copy link

danepowell commented Feb 12, 2022

Thanks, I ended up writing my own InfluxDB adaptation before running across this PR, it would have been nice to have out of the box.

In my implementation, I send a single point with multiple fields:

Point sensor("airgradient");
void loop() {
  sensor.clearFields();
  sensor.addField("pm2", PM2);
  sensor.addField("co2", CO2);
  client.writePoint(sensor);
}

I'm relatively new to InfluxDB, is there a reason to prefer using separate points as you did? Not sure of best practices. Regardless, it seems like it would be good to batch calls.

Edit: I made my implementation public: https://github.com/danepowell/AirGradient_Grafana/blob/master/AirGradient_Grafana.ino

@McJoppy
Copy link

McJoppy commented Feb 13, 2022

Yep - the, one point is best :)

FYI the code in the example also sends a single point...

// matching constant type based off info from AirGradient.h
void sendInfluxData(const int pm2, const int co2, const float temp, const int humidity) {
  influxSensor.clearFields();
  influxSensor.addField("pm2.5", pm2);
  influxSensor.addField("co2", co2);
  influxSensor.addField("temperature", temp);
  influxSensor.addField("humidity", humidity);
  
  // Print what are we exactly writing
  Serial.print("Writing: ");
  Serial.println(influxClient.pointToLineProtocol(influxSensor));

  // Write point
  if (!influxClient.writePoint(influxSensor)) {
    Serial.print("InfluxDB write failed: ");
    Serial.println(influxClient.getLastErrorMessage());
  }
}

@airgradienthq
Copy link
Owner

I cannot merge this because we have now a complete rewrite of the library published. I also would like to keep the examples here lean and focused and not have too many options that could confuse people new to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants