NO SUCH FILE OR DIRECTORY in Adruino IDE with ThingSpeak library

10 次查看(过去 30 天)
I have a project subject in University with database in ThingSpeak, I show code below like this with board ESP32. When I run with board ESP32 or ESP8266, the code announce me a error like "ThingSpeak.h: no such file or directory", although I install Thingspeak library before that. So, I need to do what to config that code. Can anyone help me? Thanks for responding or reading my problem. T.T
Error announce me inn Output:
fatal error: ThingSpeak.h: No such file or directory
compilation terminated.
My code:
#include <WiFi.h>
//#include <WiFiClient.h>
#include "ThingSpeak.h"
#define WIFI_SSID "Tang 1 Tro 198_2.4G"
#define WIFI_PASSWORD ""
#define SECRET_CH_ID 2108004
#define SECRET_WRITE_APIKEY "xxxxxxxxxxxxxxxx" // replace XYZ with your channel write API Key
#define A 35 // define MQ2 analog pin
#define D 14 // define MQ2 digital pin
#define LED 25
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
int Digital_value, Analog_value;
unsigned long dataMillis = 0;
void setup() {
Serial.begin(9600);
pinMode(A, INPUT);
pinMode(D, INPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
ThingSpeak.begin(client);
}
void loop() {
Analog_value = analogRead(A);
Digital_value = digitalRead(D);
Serial.printf("Analog value: %d\n", Analog_value);
Serial.printf("Digital value: %d\n", Digital_value);
ThingSpeak.setField(1, Analog_value);
ThingSpeak.setField(2, !Digital_value);
if (millis() - dataMillis > 20000) {
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));
}
dataMillis = millis();
}
if (!Digital_value) {
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
}
  4 个评论
Christopher Stapels
I assume you are programming in Arduino IDE? Make sure you have installed the appropriate board in boards manager, and then try removing and then reinstalling the ThingSpeak library. Occasionally I have found missing library problems related to selection of the wrong board type.

请先登录,再进行评论。

回答(0 个)

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 Write Data to Channel 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by