update Code
This commit is contained in:
parent
3c47103b39
commit
a641fad56c
119 changed files with 10997 additions and 5 deletions
59
libraries/MQTT_Client/examples/Hello/Hello.ino
Normal file
59
libraries/MQTT_Client/examples/Hello/Hello.ino
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Publishes "Hello" at regular intervals. The message can be subscribed and observed in HiveMQs
|
||||
* Websockets client http://www.hivemq.com/demos/websocket-client/
|
||||
*
|
||||
* Copyright (C) 2018 Andreas Motzek andreas-motzek@t-online.de
|
||||
*
|
||||
* You can use, redistribute and/or modify this file under the terms of the Modified Artistic License.
|
||||
* See http://simplysomethings.de/open+source/modified+artistic+license.html for details.
|
||||
*
|
||||
* This file is distributed in the hope that it will be useful, but without any warranty; without even
|
||||
* the implied warranty of merchantability or fitness for a particular purpose.
|
||||
*/
|
||||
|
||||
#include <Client.h>
|
||||
#include <WiFi101.h>
|
||||
#include <CooperativeMultitasking.h>
|
||||
#include <MQTTClient.h>
|
||||
|
||||
char ssid[] = "...";
|
||||
char pass[] = "...";
|
||||
char host[] = "broker.hivemq.com";
|
||||
char clientid[] = " ";
|
||||
char topicname[] = "amotzek/hello";
|
||||
|
||||
CooperativeMultitasking tasks;
|
||||
WiFiClient wificlient;
|
||||
MQTTClient mqttclient(&tasks, &wificlient, host, 1883, clientid, NULL, NULL);
|
||||
MQTTTopic topic(&mqttclient, topicname);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
//
|
||||
while (!Serial) {
|
||||
delay(1000);
|
||||
}
|
||||
//
|
||||
WiFi.begin(ssid, pass);
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (mqttclient.connect()) {
|
||||
topic.publish("Hello");
|
||||
//
|
||||
while (tasks.available()) {
|
||||
tasks.run();
|
||||
}
|
||||
//
|
||||
mqttclient.disconnect();
|
||||
}
|
||||
//
|
||||
switch (WiFi.status()) {
|
||||
case WL_CONNECT_FAILED:
|
||||
case WL_CONNECTION_LOST:
|
||||
case WL_DISCONNECTED: WiFi.begin(ssid, pass);
|
||||
}
|
||||
//
|
||||
delay(30000);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue