사용자 도구

사이트 도구


t_h:eth-01dv:thingspeak

ESP32 ThingSpeak에 ETH-01DV 값 게시

Step1. 아두이노 IDE에 Thingspeak 라이브러리 추가

Step2. Wi-Fi ssid, pass 확인 및 변경

  • code Thingspeak ssid, password 부분 자신이 사용할 Wi-Fi ssid, pass로 변경

Step3. Thingpeak channelnumber 및 api key 확인

  • Thingspeak → channel → my channel → channel setting → channel id 확인 후 code 변경
  • Thingspeak → channel → my channel → Api keys → Write Api key → key 확인 후 code 변경
eth-01dv_thingspeak.cpp
#include <Arduino.h>
#include "ThingSpeak.h"
#include <WiFi.h>
#define GPIO_1  1
#define GPIO_2  2
 
const char* ssid = "your network SSID";  ;   // your network SSID (name) 
const char* password = "your network PASS";  ;   // your network password
WiFiClient  client;
unsigned long myChannelNumber = your Channel number;
const char * myWriteAPIKey = " your Api key ";
// Timer variables
unsigned long lastTime = 0;
unsigned long long timerDelay = 100000;
float Temp_value[2]={0.00};
float Humi_value[2]={0.00};
void setup()
{
Serial.begin(115200);
  WiFi.mode(WIFI_STA);   
  ThingSpeak.begin(client);  // Initialize ThingSpeak
  pinMode(GPIO_1, INPUT); 
  pinMode(GPIO_2, INPUT); 
  analogReadResolution(10); // set Resolution 10 bits
}
void loop()
{
    if ((millis() - lastTime) > timerDelay) 
    {
        int temp_value = analogRead(GPIO_1);
        int humi_value = analogRead(GPIO_2);
        Serial.print("temp: ");
        Serial.print( -66.875 - 33 + 218.75 * temp_value / 1024);
        Temp_value[0] = temp_value;
        Serial.print("humi: ");
        Serial.println( -12.5 + 125 * humi_value / 1024);
        Humi_value[0] = humi_value;
        // Connect or reconnect to WiFi
        if(WiFi.status() != WL_CONNECTED)
        {
        Serial.print("Attempting to connect");
        while(WiFi.status() != WL_CONNECTED){
            WiFi.begin(ssid, password); 
            delay(2000);     
        } 
        Serial.println("\nConnected.");
        }
        // pieces of information in a channel.  Here, we write to field 1.
        ThingSpeak.setField(1, Humi_value[0]);
        ThingSpeak.setField(2, Temp_value[0]);
        int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
        if(x == 200){
        Serial.println("Channel update successful.");
        }
        else{
        Serial.println("Problem updating channel. HTTP error code " + String(x));
        }
        lastTime = millis();
   }
}
t_h/eth-01dv/thingspeak.txt · 마지막으로 수정됨: 2023/04/03 05:00 저자 mjbang