Open methaqali opened 4 years ago
unfortunately actually it is not possible to set a fixed Ip with the library, and the wifi method to set fixed ips generates conflicts with the actual way that we use the pubsubclient instance. I will add this to our feature request queue for future releases
Thank you @jotathebest for your feedback. I think this is very important feature especially for switching of data from Ubidot to local main controller - in case of interruption of internet services - and visa versa. This in fact will enhance Ubidot good contribution for IoT services and make control systems more reliable. I hope that you will try more to modify the library.
All the best.
Hi @woakas, and @jotathebest Thank you for this wonderful work. I like to add static IP to ubidots publish code in order to connect with router by this IP. I tried the following modification but it lead to appear the error in the attached screenshot. Any Suggestion is appreciated.
include "UbidotsESPMQTT.h"
/****
define TOKEN "---" // Your Ubidots TOKEN
define WIFINAME "----" //Your SSID
define WIFIPASS "-----" // Your Wifi Pass
Ubidots client(TOKEN);
/****
void callback(char topic, byte payload, unsigned int length) { Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] "); for (int i=0;i<length;i++) { Serial.print((char)payload[i]); } Serial.println(); } /****
Main Functions ****/ void setup() { IPAddress staticIP224_60(192,168,1,70); IPAddress gateway224_60(192,168,1,1); IPAddress subnet224_60(255,255,255,0); IPAddress dns224_60(192,168,1,1);// DNS server IP Serial.begin(115200); client.setDebug(true); // Pass a true or false bool value to activate debug messages WiFi.begin(WIFINAME, WIFIPASS); WiFi.config(staticIP224_60, gateway224_60, subnet224_60, dns224_60); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(F("WiFi connected")); Serial.println(F("IP address: ")); Serial.println(WiFi.localIP()); client.begin(callback); } void loop() { // put your main code here, to run repeatedly: if(!client.connected()){ client.reconnect(); }
// Publish values to 2 different data sources client.add("stuff", 10.2); //Insert your variable Labels and the value to be sent client.ubidotsPublish("source1"); client.add("stuff", 10.2); client.add("more-stuff", 120.2); client.ubidotsPublish("source2"); client.loop(); delay(5000); }