подправить скетч esp8266

Обсуждаем контроллеры компании Atmel.
Ответить
Встал на лапы
Сообщения: 138
Зарегистрирован: Вт май 30, 2017 17:42:34
Откуда: Украина.

Сообщение Funtikus »

если кому интересно, и хочет оказать помощь))

я в молодости на ассемблере spectrum такие крестики-нолики с GUI нафигачил, наши кабельщики (тв) охренели от такой красоты
но сейчас стар) может кто поможет

есть такое
Спойлер/* Sketch to collect temp and send via MQTT to web.

Must use ESP8266 Arduino from:
https://github.com/esp8266/Arduino


MQTT code Written by Tony DiCola for Adafruit Industries.
MIT license, all text above must be included in any redistribution

*/


#include <ESP8266WiFi.h>
#include <Adafruit_MQTT.h>
#include <Adafruit_MQTT_Client.h>
#include <DHT.h>


/* DHT SENSOR SETUP */

#define DHTTYPE DHT11
#define DHTPIN 2

/* WIFI SETUP */

#define WLAN_SSID "SSID" //Put your SSID here
#define WLAN_PASS "XXXXXX" //Put you wifi password here

/* ADAFRUIT IO SETUP */

#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883 // use 8883 for SSL
#define AIO_USERNAME "username" //Put your Adafruit userid here
#define AIO_KEY "000000000000" //Put your Adafruit IO key here

DHT dht(DHTPIN, DHTTYPE);

float temp_f; // Values read from sensor
String webString=""; // String to display
// Generally, you should use "unsigned long" for variables that hold time
unsigned long previousMillis = 0; // will store last temp was read
const long interval = 2300; // interval at which to read sensor

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;

// Store the MQTT server, username, and password in flash memory.

const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);

/************************* Feeds ***************************************/

// Setup a feed called 'temp' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char TEMP_FEED[] PROGMEM = AIO_USERNAME "/feeds/temp";
Adafruit_MQTT_Publish temp = Adafruit_MQTT_Publish(&mqtt, TEMP_FEED);


/********************** Sketch Code ************************************/

// Bug workaround for Arduino 1.6.6, it seems to need a function declaration
// for some reason (only affects ESP8266, likely an arduino-builder bug).
void MQTT_connect();


void setup() {
Serial.begin(115200);
delay(10);

dht.begin(); // initialize temperature sensor

Serial.println(F("MQTT Temp"));

// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);

WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();

Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());

// Get initial temp

temp_f = dht.readTemperature(true);
Serial.println();
Serial.print("Initial Temp: ");
Serial.println(temp_f);
Serial.println();
}

int delayTime = 300000; //Wait 5 minutes before sending data to web
int startDelay = 0;

void loop() {
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();


// Now we can publish stuff!

if (millis() - startDelay < delayTime) {
Serial.println ("waiting delaytime");


} else {
temp_f = dht.readTemperature(true); //Get temp in Farenheit
startDelay = millis();
Serial.print(F("\nSending temp: "));
Serial.print(temp_f);
Serial.print("...");
if (! temp.publish(temp_f)) { //Publish to Adafruit
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
}

// ping the server to keep the mqtt connection alive
// NOT required if you are publishing once every KEEPALIVE seconds

if(! mqtt.ping()) {
mqtt.disconnect();
}
}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
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!");
}
в итоге имеем ............
были варианты оно mqtt поциклу кругами
progmem? подскажите начинающему пожалуйста если не жалко
только без ссылок))
Реклама
Мучитель микросхем
Сообщения: 412
Зарегистрирован: Ср янв 04, 2012 11:57:40
Откуда: Алчевск

Сообщение Sergi »

У меня вот так конектится

WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");

ip, gateway, subnet задается чуть выше

IPAddress ip(192,168,0,99);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
Реклама
Встал на лапы
Сообщения: 138
Зарегистрирован: Вт май 30, 2017 17:42:34
Откуда: Украина.

Сообщение Funtikus »

можешь подправить? шоб я залил и оно работало?


или побратски))))) спроси чего хочешь
или сколько денег

Добавлено after 50 minutes 35 seconds:
СпойлерConnecting to MQTT...
Exception (3):
epc1=0x40206d14 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40237cac depc=0x00000000

ctx: cont
sp: 3ffffd60 end: 3fffffd0 offset: 01a0

>>>stack>>>
3fffff00: 3ffeedf4 00000000 3ffeedf4 402048c0
3fffff10: 3ffeedf4 0000000a 00000003 40204acd
3fffff20: 3ffe8c9c 000026cc 00000100 3ffe897c
3fffff30: 3ffeec4c 00000003 3ffeedf4 3ffe897c
3fffff40: 3ffeec4c 3ffeec48 3ffeedf4 3ffeedb4
3fffff50: 3fffdad0 3ffeeb28 3ffeedf4 402048c0
3fffff60: 3ffe8df4 3ffeeb28 3ffeeb28 402040ae
3fffff70: 3ffe89b0 00ffffff 3ffeedf4 40204af8
3fffff80: 3ffeec4c 3ffeec48 3ffeedf4 3ffeedb4
3fffff90: 00000003 3ffeeb28 3ffeedf4 40202af6
3fffffa0: 3fffdad0 00000000 3ffeedac 40202b48
3fffffb0: 3fffdad0 00000000 3ffeedac 40204740
3fffffc0: feefeffe feefeffe 3ffe85e4 40100739
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
vbb28d4a3
~ld
MQTT Temp


Connecting to dlink
.
WiFi connected
IP address:
192.168.0.102

Initial Temp: 78.80
Ответить

Вернуться в «AVR»