Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <Wire.h>
- #include <Adafruit_BMP085.h>
- #include <SPI.h>
- #include <Ethernet.h>
- #include <HTTPClient.h>
- #include <Cosm.h>
- #include <DHT.h>
- // Ethernet Variables
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; // MAC address for the ethernet controller.
- byte server[] = { 173,203,98,29 }; // address of the server you want to connect to (pachube.com):
- EthernetClient client;
- //DHT22 Variables
- #define DHTPIN 2
- #define DHTTYPE DHT22
- // Pachube Variables
- #define API_KEY "API ключ"
- #define FEED_ID Здесь FEED ID
- char cosmKey[] = "ключ Cosm";
- unsigned long lastConnectionTime = 0; // last time we connected to Cosm
- const unsigned long connectionInterval = 15000; // delay between connecting to Cosm in milliseconds
- // Initialize the Cosm library
- // Define the string for our datastream ID
- char sensorId[] = "Temperature";
- char bufferId[] = "Pressure";
- char sensorId2[] = "Humidity";
- //String stringId("random_string");
- const int bufferSize = 140;
- char bufferValue[bufferSize]; // enough space to store the string we're going to send
- CosmDatastream datastreams[] = {
- CosmDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
- CosmDatastream(bufferId, strlen(bufferId), DATASTREAM_FLOAT),
- CosmDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
- };
- // Wrap the datastream into a feed
- //CosmFeed feed(FEED_ID, datastreams, 1 /* number of datastreams */);
- CosmFeed feed(FEED_ID, datastreams, 3 /* number of datastreams */);
- CosmClient cosmclient(client);
- Adafruit_BMP085 bmp;
- DHT dht(DHTPIN, DHTTYPE);
- int a = 0; // из float делаем int далее в коде
- int i = 0; // счетчик циклов
- byte man_with_hat[8] =
- {
- B01100,
- B10010,
- B10010,
- B01100,
- B00000,
- B00000,
- B00000,
- B00000,
- };
- void setup()
- {
- Serial.begin(9600);
- bmp.begin();
- dht.begin();
- Serial.println("Initializing network");
- while (Ethernet.begin(mac) != 1)
- {
- Serial.println("Error getting IP address via DHCP, trying again...");
- delay(15000);
- }
- Serial.println("Network initialized");
- Serial.println();
- }
- void loop()
- {
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- // check if returns are valid, if they are NaN (not a number) then something went wrong!
- if (isnan(t) || isnan(h)) {
- Serial.println("Failed to read from DHT");
- } else {
- Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t");
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.println(" *C");
- }
- i = i + 1;
- LiquidCrystal lcd(4, 5, 9, 10, 11, 12);
- lcd.createChar(1, man_with_hat);
- lcd.begin(20, 4);
- lcd.print("t = ");
- lcd.print(bmp.readTemperature());
- lcd.print(" \1");
- lcd.print("C");
- lcd.setCursor(0, 1);
- lcd.print("P = ");
- lcd.print((bmp.readPressure()/133.3));
- lcd.print(" mm Hg");
- lcd.setCursor(0, 2);
- //АЛЬТИМЕТР (НУЖДАЕТСЯ В КОРРЕКЦИИ)
- /*
- lcd.print("Alt = ");
- lcd.print(bmp.readAltitude(101500));
- lcd.print(" m");
- */
- //ВЫВОД НА ЭКРАН ЗНАЧЕНИЯ ВЛАЖНОСТИ
- lcd.print("Hum = ");
- lcd.print(h);
- lcd.print(" %");
- /*
- //ВЫВОД НОМЕРА ИТЕРАЦИИ
- lcd.setCursor(0, 3);
- lcd.print("i = ");
- lcd.print(i);
- Serial.println(i);
- */
- delay(10000);
- if (i == 5) // задержка отправки данных на Cosm
- {
- lcd.setCursor(0, 3);
- lcd.print("Uploading it to Cosm");
- datastreams[0].setFloat(bmp.readTemperature());
- Serial.print("Read sensor value ");
- Serial.println(datastreams[0].getFloat());
- a = (bmp.readPressure()/133.3);
- datastreams[1].setFloat(a);
- datastreams[2].setFloat(h);
- Serial.print("Read sensor value ");
- Serial.println(datastreams[1].getFloat());
- Serial.println("Uploading it to Cosm");
- int ret = cosmclient.put(feed, cosmKey);
- Serial.print("cosmclient.put returned ");
- Serial.println(ret);
- Serial.println();
- i = 0;
- }
- /*
- Время задержки в мс
- 1 сек = 1000 мс
- 1 мин = 6000 мс
- */
- // delay(15000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement