thingspeak command slows down my Nodemcu execution
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
#include <ESP8266WiFi.h>
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include "secrets.h"
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
const int buttonPin = D5;
int buttonState = 0; // variable for reading the pushbutton status
long count =0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ResetPin,INPUT);
Serial.begin(115200); // Initialize serial
u8g2.begin();
delay(1000);
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(60,60,"Connecting");
u8g2.sendBuffer();
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB12_tr);
u8g2.drawStr(10,35,"CONNECTED !");
u8g2.sendBuffer();
delay(2000);
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(03,10,"Total");
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(60,60,"subscribers");
u8g2.setFont( u8g2_font_ncenB18_tn );
u8g2.setCursor(24, 40);
u8g2.print(count);
u8g2.sendBuffer();
ThingSpeak.writeField(myChannelNumber, 1, count, myWriteAPIKey);
}
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == 1)
{
count++;
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(03,10,"Total");
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(60,60,"subscribers");
u8g2.setFont( u8g2_font_ncenB18_tn );
u8g2.setCursor(24, 40);
u8g2.print(count);
u8g2.sendBuffer();
ThingSpeak.writeField(myChannelNumber, 1, count, myWriteAPIKey);
}
else
{
}
}
3 Kommentare
Christopher Stapels
am 16 Aug. 2021
Can you describe your project? What are you tring to do? What is the desired result?
I see you have a thingSpeakWrite in the setup and the loop. I dont see any delay betweeen them. If you have the button depressed on startup, that could created too frequent of write calls. Are you using the free license? if so, you would have to wait 15 seconds after startup to press the button, and 15 seconds between each bitton press.
Antworten (0)
Communitys
Weitere Antworten in ThingSpeak Community
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!