source: rtos_arduino/trunk/arduino_lib/libraries/pubsubclient-2.6/examples/mqtt_auth/mqtt_auth.ino@ 209

Last change on this file since 209 was 209, checked in by ertl-honda, 8 years ago

BlueMix用のフィアルを追加

File size: 1.1 KB
Line 
1/*
2 Basic MQTT example with Authentication
3
4 - connects to an MQTT server, providing username
5 and password
6 - publishes "hello world" to the topic "outTopic"
7 - subscribes to the topic "inTopic"
8*/
9
10#include <SPI.h>
11#include <Ethernet.h>
12#include <PubSubClient.h>
13
14// Update these with values suitable for your network.
15byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
16IPAddress ip(172, 16, 0, 100);
17IPAddress server(172, 16, 0, 2);
18
19void callback(char* topic, byte* payload, unsigned int length) {
20 // handle message arrived
21}
22
23EthernetClient ethClient;
24PubSubClient client(server, 1883, callback, ethClient);
25
26void setup()
27{
28 Ethernet.begin(mac, ip);
29 // Note - the default maximum packet size is 128 bytes. If the
30 // combined length of clientId, username and password exceed this,
31 // you will need to increase the value of MQTT_MAX_PACKET_SIZE in
32 // PubSubClient.h
33
34 if (client.connect("arduinoClient", "testuser", "testpass")) {
35 client.publish("outTopic","hello world");
36 client.subscribe("inTopic");
37 }
38}
39
40void loop()
41{
42 client.loop();
43}
Note: See TracBrowser for help on using the repository browser.