Skip to content

Static IP #14

Open
Open
@methaqali

Description

@methaqali

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions