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
19.6.2015 v 22:10
#3513
Účastník
Tady je kanál kam to chodí z ENC28J60
Tady je kód:
[code]
/*
| Post temp. values from a DS18B20 to ThingSpeak using the Ethercard interface based on the
| ENC28J60 chip.
| Based on the Ethercard example from www.jeelabs.org
| 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
#define TEMPERATURE_PRECISION 9
// 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
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
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 = "api.thingspeak.com";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");
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 () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
//timer = millis() + 60000; //Transmit every 60 seconds
timer = millis() + 30000; //Transmit every 30 seconds
sensors.requestTemperatures();
delay(200);
// 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.print("field1=");
stash.println(String(sensors.getTempC(Thermometer),DEC)); // print the temperature as string
stash.print("&field2=");
stash.print(String(sensorValue, DEC)); // print the value (0 to 1024) as string
stash.save();
// For DEBUGGING - Print out our data, uncomment the lines below
//Serial.print("field1=");
//Serial.println(sensors.getTempC(Thermometer),DEC);
//Serial.print("field2=");
//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"
"X-THINGSPEAKAPIKEY: $F" "\r\n"
"Content-Type: application/x-www-form-urlencoded" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, PSTR(APIKEY), stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}
[/code]