NodeMCU + TM1637-Anzeige | Komentor

Hallo, mein Name ist Alex Polymath. Und ich mache coole Sachen.

Hier ist ein einfaches Beispiel für NodeMCU + TM1637.
Ich verwende es, um Statistiken für meinen Dienst anzuzeigen – colorize.cc
Es ist ziemlich cool, wenn Sie ein physisches Dashboard erstellen können.

Das Schema ist einfach. NodeMCU verbindet sich mit Wi-Fi und stellt dann alle 10 Sekunden eine GET-Anfrage an meinen Server. Leider ist es mühsam, eine https-Verbindung einzurichten. Also musste ich meinen Server ändern, um ihn über http auszugeben.

#include <ESP8266WiFi.h>        // Include the Wi-Fi library
#include <ESP8266WiFiMulti.h>
#include <Arduino.h>
#include <ArduinoJson.h>
#include <TM1637Display.h>

const int CLK = D6; //Set the CLK pin connection to the display
const int DIO = D5; //Set the DIO pin connection to the display

const char* ssid     = "wifi network name";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "password wifi";     // The password of the Wi-Fi network
#include <ESP8266HTTPClient.h>

#include <Hash.h>
#define USE_SERIAL Serial

TM1637Display display(CLK, DIO); //set up the 4-Digit Display.



void setup() {
  display.setBrightness(0x0a);
  Serial.begin(115200);         // Start the Serial communication to send messages to the computer
  delay(10);
  Serial.println('\n');

  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i); Serial.print(' ');
  }

  Serial.println('\n');
  Serial.println("Connection established!");
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer


}

void loop() { 
    
          if(WiFi.status()== WL_CONNECTED){
            
            WiFiClient client;
            HTTPClient http;
            //your server address 
            String serverPath =  "
            http.begin(client, serverPath.c_str());

            int httpResponseCode = http.GET();

      if (httpResponseCode>0) {
        Serial.print("HTTP Response code: ");
        Serial.println(httpResponseCode);
        String payload = http.getString();
        Serial.println(payload.toInt());
        display.showNumberDec(payload.toInt()); //Display the numCounter value;
        
      }
      else {
        Serial.print("Error code: ");
        Serial.println(httpResponseCode);
      }
      // Free resources
      http.end();            
            
          }
          
         delay(10000);
        

  
  }

  String httpGETRequest(const char* serverName) {
  WiFiClient client;
  HTTPClient http;
    
  // Your IP address with path or Domain name with URL path 
  http.begin(client, serverName);
  
  // Send HTTP POST request
  int httpResponseCode = http.GET();
  
  String payload = "{}"; 
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  // Free resources
  http.end();

  return payload;
}

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *