Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include "Ubidots.h" //Library for uploading to Ubidots graphing service
- #include "Adafruit_Sensor.h" //Libraries for reading sensors
- #include "Adafruit_BME280.h"
- #include "math.h"
- #include "blynk.h"
- #define BME_SCK D4
- #define BME_MISO D3
- #define BME_MOSI D2
- #define BME_CS D5 //These are not needed as we're using i2c for BME not SPI
- #define do_wind FALSE //Change to TRUE when wind sensor is connected
- #define SEALEVELPRESSURE_HPA (1013.25)
- #define tempoffset -0.9F //BME temp sensor is always high by this amount
- #define TTS 1000 //Time till screen update in ms
- #define TTU 120 //Time till Ubidots update in TTS intervals
- #define TTW 120 //Time till wind update
- #define TOKEN "ix9hooYdMoBXnxoCNP65gUTNKjBG1S" // Ubidots stuff
- char auth[] = "8157361d2bf349e88d49b58c605aef00";
- Adafruit_BME280 bme; // initialize BME sensor over I2C
- float timer1 = TTU; // How often to send sensor updates to Ubidots
- float timer2 = TTW + 60;
- int screentime = (TTS / 1000);
- // diameter of anemometer
- float diameter = 2.75; //inches from center pin to middle of cup
- float mph;
- int lighton = 0;
- // read RPM
- int half_revolutions = 0;
- int avgrevs = 0;
- int revs = 0;
- float kph = 0;
- float kphavg = 0;
- int kphgust = 0;
- double windchill = 0;
- double humidex = 0;
- int ttime = 0;
- unsigned long lastmillis = 0;
- unsigned long windmillis = 0;
- unsigned long millis1 = 0;
- unsigned long millis2 = 0;
- unsigned long sleeptimer = 0;
- float deltatime = 1;
- float deltatime2 = 1;
- double pres1, temp1, hum1, abshum1, humavg, tempavg, presavg;
- float deltacount1 = 0;
- float deltacount2 = 0;
- bool ubisend = FALSE;
- bool sleepnow = FALSE;
- unsigned hours1 = 0;
- char publishString[40];
- void setup() { //This is where all Arduinos store the on-bootup code
- bme.begin();
- Blynk.begin(auth);
- Time.format(Time.now(), "%I:%M:%S%p");
- bme.setSampling(Adafruit_BME280::MODE_FORCED,
- Adafruit_BME280::SAMPLING_X1, // temperature
- Adafruit_BME280::SAMPLING_X1, // pressure
- Adafruit_BME280::SAMPLING_X1, // humidity
- Adafruit_BME280::FILTER_OFF );
- }
- void loop() { //This is where all Arduinos store their "do this all the time" code
- if (millis() - lastmillis >= TTS)
- {
- deltatime = (millis() - lastmillis) / 1000;
- deltacount1 += 1;
- deltacount2 += 1;
- lastmillis = millis(); // Update lastmillis
- bme.takeForcedMeasurement();
- pres1 += (bme.readPressure() / 100.0F);
- temp1 += (bme.readTemperature() + tempoffset);
- hum1 += bme.readHumidity();
- revs = half_revolutions * 2;
- revs = revs / deltatime;
- if (revs > kphgust) {kphgust = revs;}
- half_revolutions = 0; // Restart the RPM counter
- kph += revs;
- }
- if ((millis() - millis2) >= (timer2*1000))
- {
- deltatime2 = (millis() - millis2) / 1000;
- presavg = pres1/deltacount2;
- Blynk.virtualWrite(V2, presavg);
- Particle.publish("Pressure", String::format("%3.2f", presavg), 60, PRIVATE);
- pres1 = 0;
- deltacount2 = 0;
- }
- if ((millis() - millis1) >= (TTU*1000))
- {
- millis1 = millis();
- humavg = hum1/deltacount1;
- tempavg = temp1/deltacount1;
- abshum1 = (6.112 * pow(2.71828, ((17.67 * tempavg)/(tempavg+243.5))) * humavg * 2.1674)/(273.15 + tempavg);
- Blynk.virtualWrite(V0, tempavg);
- Blynk.virtualWrite(V1, humavg);
- Blynk.virtualWrite(V3, abshum1);
- Particle.publish("Temperature", String::format("%3.2f", tempavg), 60, PRIVATE);
- //Particle.publish("Humidity", String::format("%3.2f", humavg), 60, PRIVATE);
- Particle.publish("AbsHumidity", String::format("%3.2f", abshum1), 60, PRIVATE);
- publish_uptime();
- temp1 = 0;
- hum1 = 0;
- deltacount1 = 0;
- }
- Blynk.run();
- if (millis() >= 4294960296) {hours1 += 1193;}
- }
- void publish_uptime()
- {
- unsigned long now = millis();
- // now is in milliseconds
- float sec = now/1000;
- float hours = hours1 + (sec/3600);
- //sprintf(publishString,"%u:%u:%u",hours,min,sec);
- sprintf(publishString,"%f",hours);
- Particle.publish("Uptime hours", publishString, 60, PRIVATE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement