Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static IP #14

Open
methaqali opened this issue Nov 27, 2019 · 2 comments
Open

Static IP #14

methaqali opened this issue Nov 27, 2019 · 2 comments

Comments

@methaqali
Copy link

methaqali commented Nov 27, 2019

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 Constants
    ****************************************/
    #define TOKEN "---" // Your Ubidots TOKEN
    #define WIFINAME "----" //Your SSID
    #define WIFIPASS "-----" // Your Wifi Pass

Ubidots client(TOKEN);

/****************************************

  • Auxiliar Functions
    ****************************************/

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);
}
image

@jotathebest
Copy link
Contributor

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

@methaqali
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants