Add wider IPAddress support in api
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/*
|
||||
Basic MQTT example with Authentication
|
||||
|
||||
|
||||
- connects to an MQTT server, providing username
|
||||
and password
|
||||
- publishes "hello world" to the topic "outTopic"
|
||||
@ -13,8 +13,8 @@
|
||||
|
||||
// Update these with values suitable for your network.
|
||||
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
|
||||
byte server[] = { 172, 16, 0, 2 };
|
||||
byte ip[] = { 172, 16, 0, 100 };
|
||||
IPAddress ip(172, 16, 0, 100);
|
||||
IPAddress server(172, 16, 0, 2);
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
// handle message arrived
|
||||
@ -36,4 +36,3 @@ void loop()
|
||||
{
|
||||
client.loop();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
Basic MQTT example
|
||||
|
||||
Basic MQTT example
|
||||
|
||||
- connects to an MQTT server
|
||||
- publishes "hello world" to the topic "outTopic"
|
||||
- subscribes to the topic "inTopic"
|
||||
@ -12,8 +12,8 @@
|
||||
|
||||
// Update these with values suitable for your network.
|
||||
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
|
||||
byte server[] = { 172, 16, 0, 2 };
|
||||
byte ip[] = { 172, 16, 0, 100 };
|
||||
IPAddress ip(172, 16, 0, 100);
|
||||
IPAddress server(172, 16, 0, 2);
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
// handle message arrived
|
||||
@ -35,4 +35,3 @@ void loop()
|
||||
{
|
||||
client.loop();
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,17 @@
|
||||
/*
|
||||
Publishing in the callback
|
||||
|
||||
Publishing in the callback
|
||||
|
||||
- connects to an MQTT server
|
||||
- subscribes to the topic "inTopic"
|
||||
- when a message is received, republishes it to "outTopic"
|
||||
|
||||
|
||||
This example shows how to publish messages within the
|
||||
callback function. The callback function header needs to
|
||||
be declared before the PubSubClient constructor and the
|
||||
be declared before the PubSubClient constructor and the
|
||||
actual callback defined afterwards.
|
||||
This ensures the client reference in the callback function
|
||||
is valid.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
@ -20,8 +20,8 @@
|
||||
|
||||
// Update these with values suitable for your network.
|
||||
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
|
||||
byte server[] = { 172, 16, 0, 2 };
|
||||
byte ip[] = { 172, 16, 0, 100 };
|
||||
IPAddress ip(172, 16, 0, 100);
|
||||
IPAddress server(172, 16, 0, 2);
|
||||
|
||||
// Callback function header
|
||||
void callback(char* topic, byte* payload, unsigned int length);
|
||||
@ -34,7 +34,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
// In order to republish this payload, a copy must be made
|
||||
// as the orignal payload buffer will be overwritten whilst
|
||||
// constructing the PUBLISH packet.
|
||||
|
||||
|
||||
// Allocate the correct amount of memory for the payload copy
|
||||
byte* p = (byte*)malloc(length);
|
||||
// Copy the payload to the new buffer
|
||||
@ -46,7 +46,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
|
||||
Ethernet.begin(mac, ip);
|
||||
if (client.connect("arduinoClient")) {
|
||||
client.publish("outTopic","hello world");
|
||||
@ -58,4 +58,3 @@ void loop()
|
||||
{
|
||||
client.loop();
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
// Update these with values suitable for your network.
|
||||
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
|
||||
byte server[] = { 172, 16, 0, 2 };
|
||||
byte ip[] = { 172, 16, 0, 100 };
|
||||
IPAddress ip(172, 16, 0, 100);
|
||||
IPAddress server(172, 16, 0, 2);
|
||||
|
||||
SRAM sram(4, SRAM_1024);
|
||||
|
||||
@ -29,7 +29,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
Serial.write(sram.read());
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
|
||||
// Reset position for the next message to be stored
|
||||
sram.seek(1);
|
||||
}
|
||||
@ -47,7 +47,7 @@ void setup()
|
||||
|
||||
sram.begin();
|
||||
sram.seek(1);
|
||||
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
@ -55,4 +55,3 @@ void loop()
|
||||
{
|
||||
client.loop();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user