Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
3c581bfe3c |
|
|
@ -1,14 +1,37 @@
|
||||||
|
/*
|
||||||
|
Basic ESP8266 MQTT example
|
||||||
|
|
||||||
|
This sketch demonstrates the capabilities of the pubsub library in combination
|
||||||
|
with the ESP8266 board/library.
|
||||||
|
|
||||||
|
It connects to an MQTT server then:
|
||||||
|
- publishes "hello world" to the topic "outTopic" every two seconds
|
||||||
|
- subscribes to the topic "inTopic", printing out any messages
|
||||||
|
it receives. NB - it assumes the received payloads are strings not binary
|
||||||
|
- If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
|
||||||
|
else switch it off
|
||||||
|
|
||||||
|
It will reconnect to the server if the connection is lost using a blocking
|
||||||
|
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
|
||||||
|
achieve the same result without blocking the main loop.
|
||||||
|
|
||||||
|
To install the ESP8266 board, (using Arduino 1.6.4+):
|
||||||
|
- Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
|
||||||
|
http://arduino.esp8266.com/stable/package_esp8266com_index.json
|
||||||
|
- Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
|
||||||
|
- Select your ESP8266 in "Tools -> Board"
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
// Update these with values suitable for your network.
|
// Update these with values suitable for your network.
|
||||||
|
|
||||||
const int CONFIG_PIN = D0;
|
const char *ssid = "DEFINE_WLAN_SSID_HERE";
|
||||||
|
const char *password = "DEFINE_PASSWORD_HERE";
|
||||||
const char *ssid = "AcS";
|
const char* mqtt_server = "DEFINE_IP_HERE";
|
||||||
const char *password = "67993776724373201548";
|
const String mqtt_client = "home/S001";
|
||||||
const char* mqtt_server = "192.168.1.98";
|
|
||||||
const String mqtt_client = "home/S000";
|
|
||||||
const String mqtt_topic_t = mqtt_client + String("/temperatur");
|
const String mqtt_topic_t = mqtt_client + String("/temperatur");
|
||||||
const String mqtt_topic_h = mqtt_client + String("/humidity");
|
const String mqtt_topic_h = mqtt_client + String("/humidity");
|
||||||
const String mqtt_topic_p = mqtt_client + String("/pressure");
|
const String mqtt_topic_p = mqtt_client + String("/pressure");
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>WeatherSensor Config</title>
|
|
||||||
<style>
|
|
||||||
label { display: inline-block; width: 165px; }
|
|
||||||
h1 { text-align: center; }
|
|
||||||
div { margin: 10px 0px; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div style='margin: 0 auto; width: 400px;'>
|
|
||||||
<h1>Weather Sensor</h1>
|
|
||||||
<form id='SensorConfig' action='config' method='POST'>
|
|
||||||
<fieldset>
|
|
||||||
<legend>Config Details</legend>
|
|
||||||
<div>
|
|
||||||
<label for='ssid'>WLAN SSID:</label>
|
|
||||||
<input name='ssid' type='text' placeholder='WeatherSensorWiFi' value='' required autofocus>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for='pw'>WLAN Password:</label>
|
|
||||||
<input name='pw' type='text' placeholder='123456' required>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for='dev'>Device Name:</label>
|
|
||||||
<input name='dev' type='text' placeholder='S000' required>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<input name='config' type='submit' value='Save'>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
<form method='POST' action='update' enctype='multipart/form-data'>
|
|
||||||
<fieldset disabled='disabled'>
|
|
||||||
<legend>Firmware Update</legend>
|
|
||||||
<div>
|
|
||||||
<input type='file' name='update'>
|
|
||||||
<input type='submit' value='Update'>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>WeatherSensor Config</title>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div style='margin: 0 auto; width: 400px; text-align: center;background: #0F0; border: 1px solid #0F0;'>
|
|
||||||
<h1>Weather Sensor</h1>
|
|
||||||
<div style='background: #FFF;'>
|
|
||||||
OK
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
Disable config mode and reboot device!
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Loading…
Reference in New Issue