Zamieszczony kod , dokonuje pomiaru temperatury, narazie
Kod: Zaznacz cały
/**
* Supla.org NodeMCU WiFi minimal example
* Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>
*
* This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
*/
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>
#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO32_GLCD_HEIGHT 32
#define LOGO32_GLCD_WIDTH 32
static const unsigned char PROGMEM temp_glcd_bmp[] =
{
0x00, 0x03, 0xc0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x0e, 0x30, 0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x30, 0x0c, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0xc3, 0xc3, 0x00, 0x01, 0x87, 0xe1, 0x80,
0x03, 0x0e, 0x70, 0xc0, 0x06, 0x0d, 0xb0, 0x60, 0x0c, 0x0d, 0xb0, 0x30, 0x18, 0x0d, 0xb0, 0x18,
0x30, 0x0d, 0xb0, 0x0c, 0x30, 0x0d, 0xb0, 0x0c, 0x30, 0x0d, 0xb0, 0x0c, 0x38, 0x0d, 0xb0, 0x1c,
0x1c, 0x0d, 0xb0, 0x38, 0x0c, 0x0d, 0xb0, 0x30, 0x0c, 0x0d, 0xb0, 0x30, 0x0c, 0x0d, 0xb0, 0x30,
0x0c, 0x1d, 0xb8, 0x30, 0x0c, 0x19, 0x98, 0x30, 0x0c, 0x19, 0x98, 0x30, 0x0c, 0x19, 0x98, 0x30,
0x0c, 0x18, 0x18, 0x30, 0x0c, 0x1c, 0x38, 0x30, 0x0c, 0x0f, 0xf0, 0x30, 0x0c, 0x07, 0xe0, 0x30,
0x0c, 0x00, 0x00, 0x30, 0x0e, 0x00, 0x00, 0x70, 0x07, 0xff, 0xff, 0xe0, 0x03, 0xff, 0xff, 0xc0, };
static const unsigned char PROGMEM logo32_glcd_bmp[] =
{
// 'logo'
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00,
0x0e, 0x0e, 0x00, 0x00, 0x0c, 0x06, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00,
0x1c, 0x03, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x0e, 0x0f, 0x80, 0x00, 0x07, 0xfc, 0xe0, 0x00,
0x03, 0xf8, 0x30, 0x00, 0x00, 0xf0, 0x0d, 0xe0, 0x00, 0x10, 0x07, 0x30, 0x00, 0x18, 0x02, 0x10,
0x00, 0x18, 0x06, 0x18, 0x00, 0x08, 0x02, 0x10, 0x00, 0x08, 0x03, 0xf0, 0x00, 0x0c, 0x07, 0xc0,
0x00, 0x04, 0x0c, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00,
0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x0c, 0x20, 0x00,
0x00, 0x04, 0x40, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
WiFiClient client;
// Setup Supla connection
const char* ssid = "XXXX ";
const char* password = "XXXX";
// Setup a oneWire instance
OneWire oneWire(2); // - Pin number
// Pass oneWire reference to Dallas Temperature
DallasTemperature sensors(&oneWire);
// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {
double t = -275;
if ( sensors.getDeviceCount() > 0 )
{
sensors.requestTemperatures();
switch(channelNumber)
{
case 0:
t = sensors.getTempCByIndex(0);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setRotation(2);
display.setCursor(45,30);
display.print(t,1);
display.print((char)247);
display.println("C");
drawbitmap(temp_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
display.display();
break;
};
};
Serial.println(t);
return t;
}
void setup() {
// Init Serial port
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
// init done
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
//display.display();
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(3);
display.setTextColor(WHITE);
display.setRotation(2);
display.setCursor(30,25);
display.print("SUPLA");
drawbitmap(logo32_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
display.display();
// Init DS18B20 library
sensors.begin();
// Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
// with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
// Ethernet MAC address
uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
/*
* Having your device already registered at cloud.supla.org,
* you want to change CHANNEL sequence or remove any of them,
* then you must also remove the device itself from cloud.supla.org.
* Otherwise you will get "Channel conflict!" error.
*/
// CHANNEL0 - RELAY
SuplaDevice.addDS18B20Thermometer();
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"svr1.supla.org", // SUPLA server address
0, // Location ID
""); // Location Password
}
void loop() {
SuplaDevice.iterate();
}
void drawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons[NUMFLAKES][3];
display.drawBitmap(0,0, bitmap, w, h, WHITE);
}
// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
_supla_int_t size = client.available();
if ( size > 0 ) {
if ( size > count ) size = count;
return client.read((uint8_t *)buf, size);
};
return -1;
};
int supla_arduino_tcp_write(void *buf, int count) {
return client.write((const uint8_t *)buf, count);
};
bool supla_arduino_svr_connect(const char *server, int port) {
return client.connect(server, 2015);
}
bool supla_arduino_svr_connected(void) {
return client.connected();
}
void supla_arduino_svr_disconnect(void) {
client.stop();
}
void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {
// Serial.println("WiFi init");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
}
//Serial.print("\nlocalIP: ");
//Serial.println(WiFi.localIP());
//Serial.print("subnetMask: ");
//Serial.println(WiFi.subnetMask());
//Serial.print("gatewayIP: ");
//Serial.println(WiFi.gatewayIP());
}
SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
SuplaDeviceCallbacks cb;
cb.tcp_read = &supla_arduino_tcp_read;
cb.tcp_write = &supla_arduino_tcp_write;
cb.eth_setup = &supla_arduino_eth_setup;
cb.svr_connected = &supla_arduino_svr_connected;
cb.svr_connect = &supla_arduino_svr_connect;
cb.svr_disconnect = &supla_arduino_svr_disconnect;
cb.get_temperature = &get_temperature;
cb.get_temperature_and_humidity = NULL;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
return cb;
}