Odpověď na: Arduino ThinSpeak Měření teploty ze čtyř míst

Úvodní stránka Fórum Vaše projekty Arduino Arduino ThinSpeak Měření teploty ze čtyř míst Odpověď na: Arduino ThinSpeak Měření teploty ze čtyř míst


| Post temp. values from a DS18B20 to ThingSpeak using the Ethercard interface based on the
| ENC28J60 chip.
| Based on the Ethercard example from
| Phil Grant Jan 2014
#include <EtherCard.h>
// change these settings to match your own setup
#define APIKEY „KVWMM6N5UOKA7SR4“ // ThingSpeak Chanel 21973
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h> //DS18B20 support
// =========== Setup the Temperature sensor details =================
#define ONE_WIRE_BUS 7 // DS18B20 Temperature chip i/o on pin D7
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Insert the ID of your temp sensor here, for the sketch, visit here
DeviceAddress Thermometer = { 0x28, 0xBC, 0x28, 0xF9, 0x03, 0x00, 0x00, 0xA4 }; // zelena, adresa: 0x28, 0xBC, 0x28, 0xF9, 0x03, 0x00, 0x00, 0xA4

int sensorPin = A0; // select the input pin for the ldr
unsigned int sensorValue = 0; // variable to store the value coming from the ldr

// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0xDE,0xAD,0xBE,0xEF,0xFE,0xED };

const char website[] PROGMEM = „“;

byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;

void setup () {

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( „Failed to access Ethernet controller“);
if (!ether.dhcpSetup())
Serial.println(„DHCP failed“);

ether.printIp(„IP: „, ether.myip);
ether.printIp(„GW: „, ether.gwip);
ether.printIp(„DNS: „, ether.dnsip);

if (!ether.dnsLookup(website))
Serial.println(„DNS failed“);

ether.printIp(„SRV: „, ether.hisip);

void loop () {

if (millis() > timer) {
//timer = millis() + 60000; //Transmit every 60 seconds
timer = millis() + 30000; //Transmit every 30 seconds
// read the value from the ldr:
sensorValue = analogRead(sensorPin);
// generate two values – by using a separate stash,
// we can determine the size of the generated message ahead of time
byte sd = stash.create();
stash.println(String(sensors.getTempC(Thermometer),DEC)); // print the temperature as string
stash.print(String(sensorValue, DEC)); // print the value (0 to 1024) as string;
// For DEBUGGING – Print out our data, uncomment the lines below
//Serial.println(sensorValue, DEC); // print the value (0 to 1024)

// generate the header with payload – note that the stash size is used,
// and that a „stash descriptor“ is passed in as argument using „$H“
Stash::prepare(PSTR(„POST /update HTTP/1.1“ „\r\n“
„Host: $F“ „\r\n“
„Connection: close“ „\r\n“
„Content-Type: application/x-www-form-urlencoded“ „\r\n“
„Content-Length: $D“ „\r\n“
website, PSTR(APIKEY), stash.size(), sd);

// send the packet – this also releases all stash buffers once done