Hi, i want to create a simple wireless switch control for tasmota.
To my nodemcu, will be a button attached to GPIO 14 (D5), when pulled LOW, should connect to the main tasmota device via http command.
Im not an expert in C++ programming. I created this code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
const int ledPin = 2;
const int ButtonPin = 14;
const char* ssid = "MY SSID";
const char* psw = "MY PASSWORD";
const char* url = "http://TASMOTA_IP/cm?cmnd=POWER%20TOGGLE";
void setup() {
Serial.begin(115200);
Serial.println("TASMOTA REMOTE TOGGLE");
Serial.println("Serial Debug comm started successfully");
WiFi.begin(ssid, psw);
Serial.println("Started connection attempt to values specified in IDE");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connected!!!");}
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
int buttonstate = digitalRead(ButtonPin);
if (buttonstate == LOW) {
WiFiClient client;
Serial.println("BUTTON PRESSED- attempted a client connection to URL specified in IDE-----");
client.connect(url, 80);
delay(2000);
Serial.println("done!!!");
client.stop();
}
delay(900);
}
This is my Platformio.ini:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp12e]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps =
monitor_port =
when uploading the code via the upload function, it flashes successfully, but the ESP don’t run it.
Instead of showing normally serial output, it shows only unrecognized and crazy symbols…
What I’m doin’ wrong??
Thank you for your help!!!