Akshada Shinde in MATLAB Answers
Letzte Aktivitätam 16 Aug. 2021

#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 { } }

Info zu ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.