NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
char wifi_ssid[] = "SUPERONLINE_WiFi_5364"; // your network SSID (name)
char wifi_password[] = "nRbXNCzPQ54U"; // your network password

char * mqtt_server = "37.148.209.175";
int mqtt_port = 1993;
char * mqtt_user = "root";
char * mqtt_password = "Vr9Fr6Ge8";

#define in_topic "temp"
#define out_topic "temp"
// Replace by 2 if you aren't enable to use Serial Monitor... Don't forget to Rewire R1 to GPIO2!
#define in_led 0

WiFiClient espClient;
PubSubClient client;

void setup() {
Serial.begin(115200);
setup_wifi();
client.setClient(espClient);
client.setServer(mqtt_server, mqtt_port);
client.setCallback(callback);

// initialize digital pin LED_BUILTIN as an output.
pinMode(in_led, OUTPUT);
digitalWrite(in_led, HIGH);
}

void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(wifi_ssid);

WiFi.begin(wifi_ssid, wifi_password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
// If you do not want to use a username and password, change next line to
// if (client.connect("ESP8266Client")) {
if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

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++) {
char receivedChar = (char)payload[i];
Serial.print(receivedChar);
if (receivedChar == '0')
digitalWrite(in_led, LOW);
if (receivedChar == '1')
digitalWrite(in_led, HIGH);
}
Serial.println();
}

void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Publishes a random 0 and 1 like someone switching off and on randomly (random(2))
client.publish(out_topic, "TEMP", true);
delay(1000);
client.subscribe(in_topic);
delay(1000);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.