Close

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

#3801
marh
Účastník

arduino 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 senzore

pozri tu, teraz nie je napojene meranie , je to len stara historia
https://thingspeak.com/channels/38430

arduino 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();
  }
}