24
24
static char MQTT_HOST[48 ]; // ORGID.messaging.internetofthings.ibmcloud.com
25
25
static char MQTT_DEVICEID[30 ]; // Allocate a buffer large enough for "d:orgid:devicetype:deviceid"
26
26
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
27
30
#define MQTT_PORT 8883 // Secure MQTT 8883 / Insecure MQTT 1883
31
+ #endif
28
32
#define MQTT_TOKEN " OpenEEW-sens0r" // Watson IoT DeviceId authentication token
29
33
#define MQTT_DEVICETYPE " OpenEEW" // Watson IoT DeviceType
30
34
#define MQTT_USER " use-token-auth"
@@ -46,7 +50,11 @@ char deviceID[13];
46
50
47
51
// MQTT objects
48
52
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
50
58
PubSubClient mqtt (MQTT_HOST, MQTT_PORT, callback, wifiClient);
51
59
52
60
// Activation
@@ -729,7 +737,11 @@ void setup() {
729
737
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 ]);
730
738
Serial.println (MQTT_DEVICEID);
731
739
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
733
745
734
746
char mqttparams[100 ]; // Allocate a buffer large enough for this string ~95 chars
735
747
sprintf (mqttparams, " MQTT_USER:%s MQTT_TOKEN:%s MQTT_DEVICEID:%s" , MQTT_USER, MQTT_TOKEN, MQTT_DEVICEID);
0 commit comments