Skip to content

Commit df6158a

Browse files
committed
Run a MQTT Broker on a local subnet
Signed-off-by: John Walicki <[email protected]>
1 parent 6cebfe3 commit df6158a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

firmware/WatsonIoT/src/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@
2323
#define RECONNECTION_TO 10000 //ms
2424

2525
#define PRODUCTION_BOARD 1
26+
27+
// Run this firmware with a MQTT Broker on a local subnet
28+
//#define LOCALNET

firmware/WatsonIoT/src/main.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
static char MQTT_HOST[48]; // ORGID.messaging.internetofthings.ibmcloud.com
2525
static char MQTT_DEVICEID[30]; // Allocate a buffer large enough for "d:orgid:devicetype:deviceid"
2626
static char MQTT_ORGID[7]; // Watson IoT 6 character orgid
27+
#ifdef LOCALNET
28+
#define MQTT_PORT 1883 // Secure MQTT 8883 / Insecure MQTT 1883
29+
#else
2730
#define MQTT_PORT 8883 // Secure MQTT 8883 / Insecure MQTT 1883
31+
#endif
2832
#define MQTT_TOKEN "OpenEEW-sens0r" // Watson IoT DeviceId authentication token
2933
#define MQTT_DEVICETYPE "OpenEEW" // Watson IoT DeviceType
3034
#define MQTT_USER "use-token-auth"
@@ -46,7 +50,11 @@ char deviceID[13];
4650

4751
// MQTT objects
4852
void callback(char* topic, byte* payload, unsigned int length);
49-
WiFiClientSecure wifiClient;
53+
#ifdef LOCALNET
54+
WiFiClient wifiClient; // Insecure MQTT
55+
#else
56+
WiFiClientSecure wifiClient; // Secure MQTT
57+
#endif
5058
PubSubClient mqtt(MQTT_HOST, MQTT_PORT, callback, wifiClient);
5159

5260
// Activation
@@ -729,7 +737,11 @@ void setup() {
729737
sprintf(MQTT_DEVICEID,"d:%s:%s:%02X%02X%02X%02X%02X%02X",MQTT_ORGID,MQTT_DEVICETYPE,mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
730738
Serial.println(MQTT_DEVICEID);
731739

732-
sprintf(MQTT_HOST,"%s.messaging.internetofthings.ibmcloud.com",MQTT_ORGID);
740+
#ifdef LOCALNET
741+
sprintf(MQTT_HOST,"192.168.1.101"); // Enter the IP address of the MQTT broker on your local subnet
742+
#else
743+
sprintf(MQTT_HOST,"%s.messaging.internetofthings.ibmcloud.com",MQTT_ORGID); // Centrally managed
744+
#endif
733745

734746
char mqttparams[100]; // Allocate a buffer large enough for this string ~95 chars
735747
sprintf(mqttparams, "MQTT_USER:%s MQTT_TOKEN:%s MQTT_DEVICEID:%s", MQTT_USER, MQTT_TOKEN, MQTT_DEVICEID);

0 commit comments

Comments
 (0)