Close

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

  • 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 1 měsícem.
Aktuálně je na stránce zobrazeno 15 příspěvků - 1. až 15. (celkem z 33)
  • Autor
    Příspěvky
  • #2578
    Ondra78
    Úč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
    Zapojení na poli

    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);
    }
    
    
    #2581
    Ondra78
    Účastník


    #3510
    terje
    Účastník

    Ahoj ,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.

    #3511
    terje
    Účastník
    #3513
    Ondra78
    Úč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]
    
    #3514
    Ondra78
    Účastník

    Dával jsem to dohromady před půl rokem.

    #3535
    terje
    Účastník

    Díky, zkouším to. Zastaví se mi to na řádku byte Ethernet::buffer[700];
    Hlásí to expected initializer before buffer

    #3536
    Ondra78
    Účastník

    #3571
    terje
    Účastník

    neumím do příspěvku vložit obrázek. už jsem zkoušel všecho možné

    #3572
    Ondra78
    Účastník

    Já vkládám obrázky přes http://postimage.org/

    #3574
    terje
    Účastník

    Skončil jsem na tomhle.

    [url=http://postimg.org/image/yexblf1y3/][img]http://s17.postimg.org/yexblf1y3/Bez_n_zvu.jpg[/img][/url]

    #3575
    terje
    Účastník
    #3576
    Ondra78
    Účastník

    Postni sem kód

    #3578
    terje
    Úč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, 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();
    }
    }

    #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();
      }
    }
    
    
Aktuálně je na stránce zobrazeno 15 příspěvků - 1. až 15. (celkem z 33)
  • Pro reakci na toto téma se musíte přihlásit.