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
Označeno štítky: arduino w5100 ds18b20 thigspeak měření teplota internet
- Toto téma obsahuje celkem 32 odpovědí. Do diskuze (6 diskutujících) se naposledy zapojil uživatel nielda a poslední změna proběhla před 7 roky a 9 měsíci.
-
AutorPříspěvky
-
18.2.2015 v 9:00 #2578Ondra78Účastník
Jak už napovídá název tématu, můj projekt řeší měření teploty ze čtyř míst a logování hodnot na web .
Co k tomu potřebujeme: Arduino, Ethernet shield (W5100), snímač teploty DS18B20.
Zapojené je to takhle
[url=http://postimg.org/image/bhouqm85x/][img]http://s2.postimg.org/bhouqm85x/obrazek1.jpg[/img][/url]A ve skutečnosti na desce
A ještě odkaz na můj kanál na ThingSpeak
A ještě kód
/* Arduino --> ThingSpeak Channel via Ethernet The ThingSpeak Client sketch is designed for the Arduino and Ethernet. This sketch updates a channel feed with an analog input reading via the ThingSpeak API (http://community.thingspeak.com/documentation/) using HTTP POST. The Arduino uses DHCP and DNS for a simpler network setup. The sketch also includes a Watchdog / Reset function to make sure the Arduino stays connected and/or regains connectivity after a network outage. Use the Serial Monitor on the Arduino IDE to see verbose network feedback and ThingSpeak connectivity status. Getting Started with ThingSpeak: * Sign Up for New User Account - https://www.thingspeak.com/users/new * Register your Arduino by selecting Devices, Add New Device * Once the Arduino is registered, click Generate Unique MAC Address * Enter the new MAC Address in this sketch under "Local Network Settings" * Create a new Channel by selecting Channels and then Create New Channel * Enter the Write API Key in this sketch under "ThingSpeak Settings" Arduino Requirements: * Arduino with Ethernet Shield or Arduino Ethernet * Arduino 1.0 IDE Network Requirements: * Ethernet port on Router * DHCP enabled on Router * Unique MAC Address for Arduino Created: October 17, 2011 by Hans Scharler (http://www.iamshadowlord.com) Additional Credits: Example sketches from Arduino team, Ethernet by Adrian McEwen updated by Rick Klink to read DS18B20 temperatures and upload to thingspeak updated by Ondrej Gottwald to read 4 DS18B20 temperatures and upload to thingspeak */ #include <OneWire.h> #include <DallasTemperature.h> #include <SPI.h> #include <Ethernet.h> // Local Network Settings byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xD5, 0x63 }; // Must be unique on local network // ThingSpeak Settings char thingSpeakAddress[] = "api.thingspeak.com"; //********************************************** // Tady zadejte writeAPIkey získaný z ThingSpeak //********************************************** String writeAPIKey = "XXXXXXXXXXXXXXXX"; const int updateThingSpeakInterval = 30 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval) // Variable Setup long lastConnectionTime = 0; boolean lastConnected = false; int failedCounter = 0; // Initialize Arduino Ethernet Client EthernetClient client; // Data wire is plugged into pin 3 on the Arduino #define ONE_WIRE_BUS 3 #define TempRes 10 // set the resolution to 10 bit (resolution for ds18b20 9, 10, 11, 12) // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Assign the addresses of 1-Wire temp sensors. // Tady zadejte vlastni adresy cidel DS18B20 DeviceAddress RedTemp = { 0x28, 0xD2, 0xCA, 0xF3, 0x00, 0x00, 0x00, 0xD2 }; // ruda, adresa: 0x28, 0xD2, 0xCA, 0xF3, 0x00, 0x00, 0x00, 0xD2 DeviceAddress YellowTemp = { 0x28, 0x7E, 0x22, 0xF9, 0x03, 0x00, 0x00, 0xE8 }; // zluta, adresa: 0x28, 0x7E, 0x22, 0xF9, 0x03, 0x00, 0x00, 0xE8 DeviceAddress BlueTemp = { 0x28, 0x37, 0xBF, 0x50, 0x03, 0x00, 0x00, 0x6A }; // modra, adresa: 0x28, 0x37, 0xBF, 0x50, 0x03, 0x00, 0x00, 0x6A DeviceAddress GreenTemp = { 0x28, 0xBC, 0x28, 0xF9, 0x03, 0x00, 0x00, 0xA4 }; // zelena, adresa: 0x28, 0xBC, 0x28, 0xF9, 0x03, 0x00, 0x00, 0xA4 void setup() { // Start Serial for debugging on the Serial Monitor Serial.begin(9600); // Start Ethernet on Arduino startEthernet(); sensors.begin(); // set the resolution to TempRes value sensors.setResolution(RedTemp, TempRes); sensors.setResolution(YellowTemp, TempRes); sensors.setResolution(BlueTemp, TempRes); sensors.setResolution(GreenTemp, TempRes); } void loop(void) { // Read value from Analog Input Pin 0 //String analogPin0 = String(analogRead(A0), DEC); // Print Update Response to Serial Monitor if (client.available()) { char c = client.read(); Serial.print(c); } // Disconnect from ThingSpeak if (!client.connected() && lastConnected) { Serial.println("...disconnected"); Serial.println(); client.stop(); } //****************** //Print Temperatures //****************** Serial.print("Getting temperatures...\n\r"); sensors.requestTemperatures(); float RT = sensors.getTempC(RedTemp); //float = xx,xx ; int = xx Serial.print("Red Temp is: "); Serial.print(RT); Serial.print("C: "); Serial.print("\n\r"); float YT = sensors.getTempC(YellowTemp); //float = xx,xx ; int = xx Serial.print("Yellow Temp is: "); Serial.print(YT); Serial.print("C: "); Serial.print("\n\r"); float BT = sensors.getTempC(BlueTemp); //float = xx,xx ; int = xx Serial.print("Blue Temp is: "); Serial.print(BT); Serial.print("C: "); Serial.print("\n\r"); float GT = sensors.getTempC(GreenTemp); //float = xx,xx ; int = xx Serial.print("Green Temp is: "); Serial.print(GT); Serial.print("C: "); Serial.print("\n\r"); // Update ThingSpeak if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval)) { updateThingSpeak("field1="+String(RT, DEC)+"&field2="+String(YT, DEC)+"&field3="+String(BT, DEC)+"&field4="+String(GT, DEC)); } // Check if Arduino Ethernet needs to be restarted if (failedCounter > 3 ) {startEthernet();} lastConnected = client.connected(); } void updateThingSpeak(String tsData) { if (client.connect(thingSpeakAddress, 80)) { client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(tsData.length()); client.print("\n\n"); client.print(tsData); lastConnectionTime = millis(); if (client.connected()) { Serial.println("Connecting to ThingSpeak..."); Serial.println(); failedCounter = 0; } else { failedCounter++; Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")"); Serial.println(); } } else { failedCounter++; Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")"); Serial.println(); lastConnectionTime = millis(); } } void startEthernet() { client.stop(); Serial.println("Connecting Arduino to network..."); Serial.println(); delay(1000); // Connect to network amd obtain an IP address using DHCP if (Ethernet.begin(mac) == 0) { Serial.println("DHCP Failed, reset Arduino to try again"); Serial.println(); } else { Serial.println("Arduino connected to network using DHCP"); Serial.println(); } delay(1000); }
18.2.2015 v 9:27 #2581Ondra78Účastník
19.6.2015 v 18:29 #3510terjeÚčastníkAhoj ,funguje to perfektně. Díky. Nemohl bys poradit ,jak to rozjet se síťovým modulem (Arduino Mini Ethernet modul – ENC28J60) jsem stáhl, vložil do programu, ale na webu se nezobrazují hodnoty.Hardvéru celkem rozumím, ale programování ne.
19.6.2015 v 18:31 #3511terjeÚčastník19.6.2015 v 22:10 #3513Ondra78ÚčastníkTady 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]
19.6.2015 v 22:11 #3514Ondra78ÚčastníkDával jsem to dohromady před půl rokem.
22.6.2015 v 20:39 #3535terjeÚčastníkDíky, zkouším to. Zastaví se mi to na řádku byte Ethernet::buffer[700];
Hlásí to expected initializer before buffer22.6.2015 v 22:17 #3536Ondra78Účastník24.6.2015 v 15:40 #3571terjeÚčastníkneumím do příspěvku vložit obrázek. už jsem zkoušel všecho možné
24.6.2015 v 16:14 #3572Ondra78ÚčastníkJá vkládám obrázky přes http://postimage.org/
24.6.2015 v 16:30 #3574terjeÚčastníkSkončil jsem na tomhle.
[url=http://postimg.org/image/yexblf1y3/][img]http://s17.postimg.org/yexblf1y3/Bez_n_zvu.jpg[/img][/url]
24.6.2015 v 16:33 #357524.6.2015 v 17:11 #3576Ondra78ÚčastníkPostni sem kód
24.6.2015 v 19:31 #3578terjeÚčastník/*
| Post temp. values from a DS18B20 to ThingSpeak using the Ethercard interface based on the
| ENC28J60 chip.
| Based on the Ethercard example from http://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, 0xA4int 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();
}
}19.7.2015 v 2:16 #3801marhÚčastníkarduino nano+DS18B20+enc28j60
enc28j60 CS pin je na arduine 8
senzory sa daju upraviť ine ale ak vyhodnotenie merania je ine tak treba len upraviť kod na zistenie hodnoty na senzorepozri tu, teraz nie je napojene meranie , je to len stara historia
https://thingspeak.com/channels/38430arduino 2x 1-wire bus 4x ds18b20 thingspeak
4sensory 2x na pine 6 a 2x pine 7 —môžete dať všetky štyri na jeden Pin a zmeniť kod
dal som na 2 piny kvôli parazitnym väzbam na dlhom kabli, lebo nemeralo vždy
arduino načita teploty z Pinu 6/7
samozrejme treba upraviť kod:
pridať adresy čisiel, môžete si zmeniť nazvy a zadať kľuč pre THINGSPEAK/* | | arduino nano, 4x sensor ds18b20 on PIN6/PIN7 , used is 2x 1-wire bus | arduino program 1.6.4 | Post 4 temperatures from a DS18B20 to ThingSpeak using the Ethercard interface based on the | ENC28J60 chip. ethercard <EtherCard.h> from master | Based on the Ethercard example from www.jeelabs.org | enc28j60 CS is pin 8 | library ethercard from master , ethercardmaster.zip | Phil Grant Jan 2014 */ #include <EtherCard.h> // change these settings to match your own setup #define APIKEY "C06FVBVE5DCU0UK1 " // plug your API KEY #include <Wire.h> #include <OneWire.h> #include <DallasTemperature.h> //DS18B20 support // =========== Setup the Temperature sensor details ================= #define TEMPERATURE_PRECISION 9 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWireA (6) ; // 2 sensor on pin6 OneWire oneWireB (7) ; // 2 sensor on pin7 // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensorsA (&oneWireA) ; DallasTemperature sensorsB (&oneWireB) ; // 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 inside = { 0x28, 0xFF, 0x1F, 0x8A, 0x4E, 0x04, 0x00, 0x67 }; DeviceAddress outside = { 0x28, 0xFF, 0x03, 0x4A, 0x33, 0x04, 0x00, 0xFC }; DeviceAddress dogHouse = { 0x28, 0xFF, 0xE2, 0x44, 0x31, 0x04, 0x00, 0xB1 }; DeviceAddress cathouse = { 0x28, 0xFF, 0xED, 0x89, 0x4E, 0x04, 0x00, 0xCA }; // 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() + 15000; //Transmit every minute // themperatures from all sensors sensorsA.requestTemperatures(); sensorsB.requestTemperatures(); // save themperatures to values float aThermometer = sensorsA.getTempC(inside); float aThermometer1 = sensorsA.getTempC(outside); float aThermometer2 = sensorsB.getTempC(dogHouse); float aThermometer3 = sensorsB.getTempC(cathouse); delay(200); // generate two fake values as payload - by using a separate stash, // we can determine the size of the generated message ahead of time byte sd = stash.create(); // create text with values for THINGSPEAK with more fields stash.print("field1="); stash.println(aThermometer); stash.print("&field2="); stash.println(aThermometer1); stash.print("&field3="); stash.println(aThermometer2); stash.print("&field4="); stash.println(aThermometer3); stash.save(); // 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(); } }
—–
web_tepl_thingspeak 2 sensors.ino
2 senzory na jednom pine/* | Post temp. values from a DS18B20 to ThingSpeak using the Ethercard interface based on the | ENC28J60 chip. ethercard arduino 1.6.4 <EtherCard.h> from master | Based on the Ethercard example from www.jeelabs.org | enc28j60 CS is pin 8 | library ethercard from master , ethercardmaster.zip | Phil Grant Jan 2014 */ #include <EtherCard.h> // change these settings to match your own setup #define APIKEY "C06FVBVE5DCU0UK1 " // plug your API KEY #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, plug sensors to PIN D7, or change value #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, 0x5C, 0x46, 0xB4, 0x01, 0x00, 0x00, 0x0C }; // ds18b20 address, replace with your address DeviceAddress Thermometer1 = { 0x28, 0xFF, 0xE2, 0x44, 0x31, 0x04, 0x00, 0xB1 }; // ds18b20 address,replace with your address you can others sensors // you can others sensors // 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() + 15000; //Transmit every minute // themperatures from all sensors sensors.requestTemperatures(); // save themperatures to values float aThermometer = sensors.getTempC(Thermometer); float aThermometer1 = sensors.getTempC(Thermometer1); delay(200); // generate two fake values as payload - by using a separate stash, // we can determine the size of the generated message ahead of time byte sd = stash.create(); // create text with values for THINGSPEAK with more fields stash.print("field1="); stash.println(aThermometer); stash.print("&field2="); stash.println(aThermometer1); stash.save(); // 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(); } }
29.7.2015 v 13:44 #3885terjeÚčastníkDíky,funguje. Ještě dotaz. Dá se na thingspeak získat nějaká historie dat nebo jen to co je tam aktuálně zobrazeno.
29.7.2015 v 15:27 #3886Ondra78ÚčastníkAno, /export/-Download all of this Channel’s feeds in CSV format.
10.8.2015 v 15:20 #4043terjeÚčastníkChlapi díky. Jestli se chcete podívat na můj kanál, tak uživatel „terje_ard“. Zatím jenom ze dvou čidel.
8.12.2015 v 20:09 #5409mapeÚčastníkAhoj borci; v první řadě bych vám chtěl poděkovat, že jsem díky vám zprovoznil logování teploty na ThingSpeak. Kompilátor mi neustále házel chyby a po promarněném víkendu, kdy už jsem chtěl moduly vyhodit z okna :)) jsem si všimnul, že Ondra78 používá verzi 1.6.3 a přitom web arduina mi vnutil 1.6.5, která ten kód vyhodnotí s chybami. Takže to bych chtěl napsat pro všechny ostatní, aby neztráceli naději 😀
A teď k mojí otázce: mám takovýto testovací program#include <EtherCard.h> #define APIKEY "ZMH0T5WDETDGCY67" #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 3 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); 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(9600); Serial.println("\n[webClient]"); sensors.begin(); 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 () { sensors.requestTemperatures(); ether.packetLoop(ether.packetReceive()); if (millis() > timer) { Serial.println(millis()); timer = millis() + 660000; delay(200); byte sd = stash.create(); stash.print("&field1="); stash.print(String(sensors.getTempCByIndex(0), DEC)); // print the value (0 to 1024) as string stash.save(); 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); ether.tcpSend(); } }
Funguje to, ale pouze 10 minut, pak se musí přípravek resetovat, proč? Přes sériovou linku vidim, že program žije a v intervalech nastavených v programu problikne i ethernetový modul a dioda na routeru. Vygooglil jsem, že TCP protokol má timeout 10 minut, ale moc tomu nerozumim, je to pravda? Jak tedy upravit program? A jak je možný, že vám to funguje bez problému? Neni případně problém na mojim routeru? Řeším to teď teda tak, že mám časové relé, které mi zapíná modul (nano + mini ethernet modul HR911105A) jednou za 30minut na 1minutu. Děkuji za každou radu.
11.12.2015 v 10:33 #5413AlešÚčastníkZkoušel jsi ten interval zkrátit třeba na 2 minuty? Jak se to bude chovat ?
11.12.2015 v 11:36 #5414mapeÚčastníkVypadne to po 10ti minutách, takže výsledků bude 5-6. Když udělám interval 30s, bude výsledků víc, ale zase pouze 10minut.
11.12.2015 v 12:38 #5415AlešÚčastníkTo je divné. V meteostanici http://xanadu.khnet.info/meteo.php mám ethernet shield nastavený na pevnou IP adresu, data se odesílají každou minutu, a běží to naprosto bez problému asi 2 roky. To samé přes WiFi s ESP8266 se data odesílají na ThinSpeak každých 5 minut, a také to jede v kuse třeba měsíc.
Zkusil bych nastavit pevnou IP adresu. Když to nepomůže, tak zkusit vytvořit krátký prográmek, který bude odněkud stahovat (GET) nějaká data v intervalu např. 2 minut, a sledovat, jestli to také vypadne.11.12.2015 v 13:29 #5416mapeÚčastníkJá mám ten malej ethernetovej modul, nikoliv ethernet shield. Se statickou IP adresou to funguje normálně. Ale proč s DHCP ne? Píše se o tom i tady
https://forum.arduino.cc/index.php?topic=302559.0
ale týpek to „vyřešil“ tim, že si koupil rovnou nový modul.11.12.2015 v 15:05 #5417AlešÚčastníkAha. Tak to je jasné. DHCP server má nastavený Lease time na 10minut. To je doba na kterou ti DHCP server přidělí IP adresu. Když se těch 10 minut nic neděje, tak ji odpojí, a může ji přidělit jinému zařízení. Na 10 minut se nastavuje jenom v místě, kde se připojuje hodně lidí na krátkou dobu – třeba free WiFi na nádraží apod. Běžně je nastavujena na 1440 minut, já ho mám doma nastavený na 0 – neomezeně. Takže buď přenastavit lease time, nebo to vyřešit tak, jak je to popsané v jednom z příspěvků z toho fóra:
Then try this code. It connects to a server every 30 seconds. See how long it goes.
https://playground.arduino.cc/Code/WebClient
It has the dhcp begin call commented out, but the code is there to use it.Místo čekání x minut tam udělat smyčku, která každých 30s stáhne něco odněkud z webu. Potom by měla i vydržet ta pronajatá IP adresa.
Nebo nechat nastavenou pevnou IP adresu.
11.12.2015 v 15:22 #5418AlešÚčastníkTeď ale koukám, že ten příklad je pro w5100/w5200 🙁
11.12.2015 v 15:44 #5419AlešÚčastníkTady jsem našel nějakou úpravu: http://stackoverflow.com/questions/33689096/arduino-ethercard-dhcp-leasetime
27.2.2017 v 18:52 #10627nieldaÚčastníkAhoj. Možná mám úplně hloupý dotaz, ale třeba mi pomůžeš. V oblasti Arduina jsem začátečník a programování se taky učím. Chtěl jsem si vyzkoušet tvůj program, ale nevím jak z Code uvedeném v článku to dostanu do srozumitelného stavu pro IDE. Moc dík.
28.2.2017 v 6:33 #10643Ondra78Účastníknielda > koho se ptáš? CTRLc a CTRLv nefunguje?
28.2.2017 v 10:35 #10644nieldaÚčastníkTo samozřejmě funguje. Ale pokud to takto přes schránku zkopíruji. Je vše v jednom bloku bez struktury a řádkovaní. Asi to dělám blbě.
28.2.2017 v 11:42 #10645Ondra78ÚčastníkTeď jsem to zkoušel a v pohodě.
OS: Linux Mint 17.3
prohlížeč:FireFox 51.0.1
IDE: 1.6.12 -
AutorPříspěvky
- Pro reakci na toto téma se musíte přihlásit.