Juraj:
so let start from the beginning. the Zero has native USB port configured as Serial and UART configured Serial1. I expect that you connected the esp8266 module to Serial1.
Half correct, I have the programming USB port configured as Serial. Using the Serial Monitor, I cannot get AT commands to work on the Native USB port, only on the Programming port.
Juraj:
what do you want to flash into esp8266. you don't want to use AT firmware?
I'm intending on flashing this, as I have no clue how I would do this through the AT stuff.
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define WIFI_SSID "WirelessL"
#define WIFI_PASS "3038861117"
#define MQTT_SERV "io.adafruit.com"
#define MQTT_PORT 1883
#define MQTT_NAME "Java_SE_Binary"
#define MQTT_PASS "74ba791825fc48bfa7cdcd86c9b4c339"
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);
Adafruit_MQTT_Subscribe onoff = Adafruit_MQTT_Subscribe(&mqtt, MQTT_NAME "/f/onoff");
void setup()
{
Serial.begin(115200);
//Connect to WiFi
Serial.print("\n\nConnecting Wifi... ");
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
Serial.println("OK!");
//Subscribe to the onoff topic
mqtt.subscribe(&onoff);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
//Connect/Reconnect to MQTT
MQTT_connect();
//Read from our subscription queue until we run out, or
//wait up to 5 seconds for subscription to update
Adafruit_MQTT_Subscribe * subscription;
while ((subscription = mqtt.readSubscription(5000)))
{
//If we're in here, a subscription updated...
if (subscription == &onoff)
{
//Print the new value to the serial monitor
Serial.print("onoff: ");
Serial.println((char*) onoff.lastread);
//If the new value is "ON", turn the light on.
//Otherwise, turn it off.
if (!strcmp((char*) onoff.lastread, "ON"))
{
//active low logic
digitalWrite(LED_BUILTIN, LOW);
}
else
{
digitalWrite(LED_BUILTIN, HIGH);
}
}
}
// ping the server to keep the mqtt connection alive
if (!mqtt.ping()){
mqtt.disconnect();
}
}
void MQTT_connect()
{
int8_t ret;
// Stop if already connected
if (mqtt.connected())
{
return;
}
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) // connect will return 0 for connected
{
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0)
{
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}
Juraj:
and if you still want to use and flash the esp8266 with Zero, you can use EspProxy
I gave it a try, and got a nice, nasty error. Will make another reply because character limits.