NodeMCU - Spezifikationen
Bei ebay kann das Board NodeMCU ESP-WROOM-32 für wenige Euros bestellt werden. Es hat WiFi und Bluetooth onboard, 448 KByte ROM, 520 KByte SRAM,16 KByte SRAM in RTC.
Einige weitere Features:
- 12-bit SAR ADC up to 18 channels
- 2 × 8-bit D/A converters
- 10 × touch sensors
- Temperature sensor
- 4 × SPI, 2 × I2S, 2 × I2C, 3 × UART
- 1 host (SD/eMMC/SDIO), 1 slave (SDIO/SPI)
- IR (TX/RX)
- Motor PWM, LED PWM up to 16 channels
- Hall sensor
Board-Installation für die Arduino-IDE:
Unter Einstellungen/Boards muss die URL https://dl.espressif.com/dl/package_esp32_index.json eingegebene werden. Danach kann unter Boards das passende Modul ausgewählt werden. Bei mir war es das Board “NodeMCU-32S.
WiFi-Betrieb:
#include <WiFi.h> #include "soc/soc.h" #include "soc/rtc_cntl_reg.h" #include <HTTPClient.h> const char* ssid = "xxxxx"; const char* password = "xxxxxxxxxxxxxxxxxxxxxxxx"; void setup() { WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector Serial.begin(115200); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.println("Connecting to WiFi.."); } Serial.println("Connected to the WiFi network"); }
Die Bibliotheken soc/xxx habe ich benötigt, da immer die Fehlermeldung “brownout …” erschien, die mit diesem patch abgeschaltet wird. Die Verbindung hat dann geklappt.
Testweise habe ich von einem Web-Server eine php-Seite aufgerufen, die nur einen einfachen String zurückliefert. Diesen kann man dann über den seriellen Monitor anzeigen.
void loop() { if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status HTTPClient http; http.begin("http://192.168.2.103/getWetter.php"); //Specify the URL int httpCode = http.GET(); //Make the request if (httpCode > 0) { //Check for the returning code String antwort = http.getString(); Serial.println(httpCode); Serial.println(antwort); } else { Serial.println("Error on HTTP request"); } http.end(); //Free the resources } delay(10000); }
Die php-Testdatei kann zum Beispiel folgende Miniform haben:
<?php echo "hello world!"; ?>