hat jemand schon mal einen ESP8266 mit einem nano verbunden und dann via mqtt daten übertragen?
alles was ich bisher finden konnte waren nur beispiele wo der ganze mqtt kram auf dem esp selbst installiert ist, das will ich aber nicht, da mir dieser für alle angedachten aufgaben zu klein ist.
den esp selbst mit dem nano zu verbinden via softserial und at-befehlen hab ich hinbekommen.
Hat schon einen Grund, warum in den Beispielen immer der Ganze mqtt Kram auf dem esp läuft. Der ist ja auch viel leistungsfähiger. Mach doch die Kommunikation zwischen esp und nano via i2c, nano natürlich als slave.
ich brauche keine große leistung sondern nur ein paar mehr i/o's.
und dafür das ganze zweiteilig erscheint mir etwas sehr aufwendig, zumal man m.w. den esp nicht "so einfach" an den rechner anschließen kann. und ständig ab und dran nur um was zu debuggen habe ich auch wenig lust.
ich konnte bisher nix genaues zu mqtt und at befehlen finden ...
dem stimme ich dir ja zu, aber ich will doch eigentlich nix weiter als, ermittelte werte (ja kann man vielleicht auch mit dem esp machen, ich habe aber im moment nur unos, megas und nanos und 2-3 von den esp modulen) an meinen internen server zu übermitteln.
dachte das ginge mit dem esp in kombination mit dem nano als tcp-client.
ich dachte anfangs, ich rufe einfach ne popelige php-webseite auf und übermittle die werte als parameter.
ich habe auch ein sketch irgendwo, der genau das macht, allerdings kriege ich den nicht so hin, dass ich den web aufruf mehrfach im loop machen kann.
da ich eh mosquitto und openhab laufen habe, kam mir der gedanke das mit mqtt zu machen.
ich hänge mal mein sketch hier dran, das war bisher nur der anfang ...
#include "Dht11.h"
#include <Adafruit_ESP8266.h>
#include <SoftwareSerial.h>
#include <PubSubClient.h>
#define ESP_RX 10
#define ESP_TX 11
#define ESP_RST 3
#define ESP_SSID "s1s2i3d4" // Your network name here
#define ESP_PASS "p1a2s3s4w5o6r7d8" // Your network password here
#define HOST "1.2.3.4" // Host to contact
#define PAGE "/esp_ctrl_01.php" // Web page to request
#define PORT 80 // 8080 = HTTP default port
#define LED_PIN 13
enum
{
// The data I/O pin connected to the DHT11 sensor
DHT_DATA_PIN = 2,
// The baud rate of the serial interface
ESP_SERIAL_BAUD = 9600,
SER_SERIAL_BAUD = 115200,
// The delay between sensor polls.
POLL_DELAY = 1000,
};
int chk;
SoftwareSerial ESP_SoftSerial(ESP_RX, ESP_TX);
Adafruit_ESP8266 wifi(&ESP_SoftSerial, &Serial, ESP_RST);
boolean gotIPAdr = false;
void setup()
{
char buffer[50];
// Flash LED on power-up
pinMode(LED_PIN, OUTPUT);
for (uint8_t i = 0; i < 3; i++)
{
digitalWrite(13, HIGH); delay(50);
digitalWrite(13, LOW); delay(100);
}
wifi.setBootMarker(F("Version:0.9.2.4]\r\n\r\nready")); // This might work with other firmware versions (no guarantees) // by providing a string to ID the tail end of the boot message: // comment/replace this if you are using something other than v 0.9.2.4!
ESP_SoftSerial.begin(ESP_SERIAL_BAUD); // Soft serial connection to ESP8266
Serial.begin(SER_SERIAL_BAUD);
while (!Serial); // UART serial debug
Serial.println(F("ESP-Control-01"));
// Test if module is ready
Serial.println(F("WiFi-Modul: Hard-Reset"));
if (!wifi.hardReset())
{
Serial.println(F("WiFi-Modul: nicht gefunden"));
for (;;);
}
Serial.println(F("OK."));
Serial.println(F("WiFi-Modul: Soft-Reset"));
if (!wifi.softReset())
{
Serial.println(F("WiFi-Modul: keine Antwort"));
for (;;);
}
Serial.println(F("OK."));
Serial.println(F("WiFi-Modul: Check Firmware"));
wifi.println(F("AT+GMR"));
if (wifi.readLine(buffer, sizeof(buffer)))
{
Serial.println(buffer);
wifi.find(); // Discard the 'OK' that follows
}
else
{
Serial.println(F("WiFi-Modul: Fehler"));
}
Serial.println(F("WiFi-Modul: Verbinde zu WiFi-Access-Point"));
if (wifi.connectToAP(F(ESP_SSID), F(ESP_PASS)))
{
// IP addr check isn't part of library yet, but
// we can manually request and place in a string.
Serial.println(F("OK"));
Serial.println(F("WiFi-Modul: IP-Adresse: "));
wifi.println(F("AT+CIFSR"));
if (wifi.readLine(buffer, sizeof(buffer)))
{
Serial.println(buffer);
wifi.find(); // Discard the 'OK' that follows
gotIPAdr = true;
}
else
{
// IP addr check failed
gotIPAdr = false;
Serial.println(F("WiFi-Modul: Keine IP-Adresse"));
}
//wifi.closeAP();
}
else
{
// WiFi connection failed
Serial.println(F("WiFi-Modul: Fataler Fehler"));
}
}
void loop()
{
static Dht11 sensor(DHT_DATA_PIN);
switch (sensor.read())
{
case Dht11::OK:
//Serial.print(F("Hum. (%): "));
//Serial.println(sensor.getHumidity());
//Serial.print(F("Temp. (C): "));
Serial.println(sensor.getTemperature());
break;
case Dht11::ERROR_CHECKSUM:
Serial.println(F("Checksum error"));
break;
case Dht11::ERROR_TIMEOUT:
Serial.println(F("Timeout error"));
break;
default:
Serial.println(F("Unknown error"));
break;
}
if (gotIPAdr)
{
Serial.println(F("Connecting to host..."));
if (wifi.connectTCP(F(HOST), PORT))
{
Serial.println(F("OK\nRequesting page..."));
if (wifi.requestURL(F(PAGE)))
{
Serial.println("OK\nSearching for string...");
// Search for a phrase in the open stream.
// Must be a flash-resident string (F()).
if (wifi.find(F("working"), true))
{
Serial.println(F("found!"));
}
else
{
Serial.println(F("not found."));
}
}
else
{ // URL request failed
Serial.println(F("error"));
}
wifi.find(); // Discard the 'OK' that follows
wifi.closeTCP();
}
else
{
// TCP connect failed
Serial.println(F("D'oh!"));
}
wifi.closeAP();
}
//Serial.println("");
Serial.print(F("\n......................."));
delay(POLL_DELAY);
Serial.println(F("\n.......................\n\n\n"));
}
/*------------------------------------------------------------------------
Simple ESP8266 test. Requires SoftwareSerial and an ESP8266 that's been
flashed with recent 'AT' firmware operating at 9600 baud. Only tested
w/Adafruit-programmed modules: https://www.adafruit.com/product/2282
The ESP8266 is a 3.3V device. Safe operation with 5V devices (most
Arduino boards) requires a logic-level shifter for TX and RX signals.
------------------------------------------------------------------------*/
#include <Adafruit_ESP8266.h>
#include <SoftwareSerial.h>
#define ESP_RX 2
#define ESP_TX 3
#define ESP_RST 4
SoftwareSerial softser(ESP_RX, ESP_TX);
// Must declare output stream before Adafruit_ESP8266 constructor; can be
// a SoftwareSerial stream, or Serial/Serial1/etc. for UART.
Adafruit_ESP8266 wifi(&softser, &Serial, ESP_RST);
// Must call begin() on the stream(s) before using Adafruit_ESP8266 object.
#define ESP_SSID "SSIDNAME" // Your network name here
#define ESP_PASS "PASSWORD" // Your network password here
#define HOST "www.adafruit.com" // Host to contact
#define PAGE "/testwifi/index.html" // Web page to request
#define PORT 80 // 80 = HTTP default port
#define LED_PIN 13
void setup() {
char buffer[50];
// Flash LED on power-up
pinMode(LED_PIN, OUTPUT);
for(uint8_t i=0; i<3; i++) {
digitalWrite(13, HIGH); delay(50);
digitalWrite(13, LOW); delay(100);
}
// This might work with other firmware versions (no guarantees)
// by providing a string to ID the tail end of the boot message:
// comment/replace this if you are using something other than v 0.9.2.4!
wifi.setBootMarker(F("Version:0.9.2.4]\r\n\r\nready"));
softser.begin(9600); // Soft serial connection to ESP8266
Serial.begin(57600); while(!Serial); // UART serial debug
Serial.println(F("Adafruit ESP8266 Demo"));
// Test if module is ready
Serial.print(F("Hard reset..."));
if(!wifi.hardReset()) {
Serial.println(F("no response from module."));
for(;;);
}
Serial.println(F("OK."));
Serial.print(F("Soft reset..."));
if(!wifi.softReset()) {
Serial.println(F("no response from module."));
for(;;);
}
Serial.println(F("OK."));
Serial.print(F("Checking firmware version..."));
wifi.println(F("AT+GMR"));
if(wifi.readLine(buffer, sizeof(buffer))) {
Serial.println(buffer);
wifi.find(); // Discard the 'OK' that follows
} else {
Serial.println(F("error"));
}
Serial.print(F("Connecting to WiFi..."));
if(wifi.connectToAP(F(ESP_SSID), F(ESP_PASS))) {
// IP addr check isn't part of library yet, but
// we can manually request and place in a string.
Serial.print(F("OK\nChecking IP addr..."));
wifi.println(F("AT+CIFSR"));
if(wifi.readLine(buffer, sizeof(buffer))) {
Serial.println(buffer);
wifi.find(); // Discard the 'OK' that follows
Serial.print(F("Connecting to host..."));
if(wifi.connectTCP(F(HOST), PORT)) {
Serial.print(F("OK\nRequesting page..."));
if(wifi.requestURL(F(PAGE))) {
Serial.println("OK\nSearching for string...");
// Search for a phrase in the open stream.
// Must be a flash-resident string (F()).
if(wifi.find(F("working"), true)) {
Serial.println(F("found!"));
} else {
Serial.println(F("not found."));
}
} else { // URL request failed
Serial.println(F("error"));
}
wifi.closeTCP();
} else { // TCP connect failed
Serial.println(F("D'oh!"));
}
} else { // IP addr check failed
Serial.println(F("error"));
}
wifi.closeAP();
} else { // WiFi connection failed
Serial.println(F("FAIL"));
}
}
void loop() {
}