BASIC4MCU | 질문게시판 | mcm보드 thingspeak voltage코딩
페이지 정보
작성자 엘도라도 작성일2019-11-06 13:41 조회9,738회 댓글2건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=10551
본문
node mcu보드에 씽스피크writevoltage를 코딩하려는데 ssid,pw,씽스피크id,api키를 넣어봐도 연결이 안되네요 ssid,pw넣는곳이 2곳인데 2곳 모두넣어봐도 않되네요 ㅜ
/*
WriteVoltage
Reads an analog voltage from pin 0, and writes it to a channel on ThingSpeak every 20 seconds.
ThingSpeak (https://www.thingspeak.com ) is a free IoT service for prototyping
systems that collect, analyze, and react to their environments.
Copyright 2015, The MathWorks, Inc.
Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed.
See the accompaning licence file for licensing information.
*/
#ifdef SPARK
#include "ThingSpeak/ThingSpeak.h"
#else
#include "ThingSpeak.h"
#endif
/// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported.
// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield)
// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below
// ***********************************************************************************************************
//#define USE_WIFI_SHIELD
#ifdef ARDUINO_ARCH_AVR
#ifdef ARDUINO_AVR_YUN
#include "YunClient.h"
YunClient client;
#else
#ifdef USE_WIFI_SHIELD
#include <SPI.h>
// ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes
// If you get "multiple definition of `WiFi'" -- comment out the line below.
#include <WiFi.h>
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#else
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
#endif
#endif
// On Arduino: 0 - 1023 maps to 0 - 5 volts
#define VOLTAGE_MAX 5.0
#define VOLTAGE_MAXCOUNTS 1023.0
#endif
#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
// On ESP8266: 0 - 1023 maps to 0 - 1 volts
#define VOLTAGE_MAX 1.0
#define VOLTAGE_MAXCOUNTS 1023.0
#endif
#ifdef SPARK
TCPClient client;
// On Particle: 0 - 4095 maps to 0 - 3.3 volts
#define VOLTAGE_MAX 3.3
#define VOLTAGE_MAXCOUNTS 4095.0
#endif
/*
*****************************************************************************************
**** Visithttps://www.thingspeak.com to sign up for a free account and create
**** a channel. The video tutorialhttp://community.thingspeak.com/tutorials/thingspeak-channels/
**** has more information. You need to change this to your channel, and your write API key
**** IF YOU SHARE YOUR CODE WITH OTHERS, MAKE SURE YOU REMOVE YOUR WRITE API KEY!!
*****************************************************************************************/
unsigned long myChannelNumber = 31461;
const char * myWriteAPIKey = "LD79EOAAWRVYF04Y";
void setup() {
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
#ifdef ARDUINO_AVR_YUN
Bridge.begin();
#else
#if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266)
WiFi.begin(ssid, pass);
#else
Ethernet.begin(mac);
#endif
#endif
#endif
ThingSpeak.begin(client);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading
// On Arduino: 0 - 1023 maps to 0 - 5 volts
// On ESP8266: 0 - 1023 maps to 0 - 1 volts
// On Particle: 0 - 4095 maps to 0 - 3.3 volts
float voltage = sensorValue * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}
댓글 2
조회수 9,738master님의 댓글
master 작성일
https://www.google.com/search?q=node+mcu+ThingSpeak&pws=0&gl=us&gws_rd=cr
유사한 예제를 찾아서 동작시킨 후에
소스를 공부해서 이해 하세요
그 후에 원하는대로 수정해서 만들면 수월합니다.
master님의 댓글
master 작성일
보통 라이브러리를 설치하면
라이브러리에 딸린 예제소스도 함께 설치됩니다.
파일/예제/라이브러리예제 를 찾아보세요