Skip to content

Commit b2da4d9

Browse files
committed
Some changes
1 parent e360d2a commit b2da4d9

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

mqtt_lcd/mqtt_lcd.ino

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,46 @@ EthernetClient ethClient; // Ethernet object
3434
PubSubClient client( MQTT_SERVER, 1883, callback, ethClient); // MQTT object
3535

3636
void setup() {
37+
// set random MaAC
38+
for (byte i = 1; i < 6; ++i) {
39+
MAC_ADDRESS[i] = random(0,255);
40+
}
41+
3742
Serial.begin(57600);
3843
lcd.begin(16, 2);
3944
lcd.setBacklight(WHITE);
45+
randomSeed(analogRead(0));
46+
4047

41-
Serial.println("Net begin");
48+
lcd.clear();
49+
lcd.setCursor(0, 0);
50+
lcd.print("DHCP...");
51+
lcd.setCursor(0, 1);
52+
Serial.println("DHCP...");
4253

4354
pinMode(LEDpin, OUTPUT);
4455

4556
if (Ethernet.begin(MAC_ADDRESS) == 0) // Get connected!
4657
{
4758
Serial.println("Failed to configure Ethernet using DHCP");
59+
lcd.print("DHCP failed");
4860
return;
49-
}
50-
51-
Serial.print("IP: "); // A little debug.. show IP address
52-
Serial.println(Ethernet.localIP());
61+
} else {
62+
Serial.print("IP: "); // A little debug.. show IP address
63+
Serial.println(Ethernet.localIP());
5364

65+
for (byte thisByte = 0; thisByte < 4; thisByte++) {
66+
// print the value of each byte of the IP address:
67+
Serial.print(Ethernet.localIP()[thisByte], DEC);
68+
lcd.print(Ethernet.localIP()[thisByte], DEC);
69+
if (thisByte < 3) {
70+
Serial.print(".");
71+
lcd.print(".");
72+
}
73+
}
74+
delay(2000);
75+
}
76+
5477
if (client.connect("arduinoClient")) { // connect to MQTT server
5578
client.subscribe("sensors/+/+"); // subscribe to topic "rgblight"
5679
Serial.println("Connected to MQTT"); // let us know this has happened
@@ -73,12 +96,17 @@ void callback(char* topic, byte* payload, unsigned int length) {
7396
Serial.print('\t');
7497
Serial.println(topic);
7598

76-
lcd.setCursor(0,0);
77-
for (i = 0; i < 16; i++) {
78-
lcd.print(" ");
79-
}
99+
// lcd.setCursor(0,0);
100+
// for (i = 0; i < 16; i++) {
101+
// lcd.print(" ");
102+
// }
80103
lcd.setCursor(0, 0);
81104
lcd.print(topic+8);
105+
lcd.print(" ");
106+
// for (i = topic.length(); i < 16; i++) {
107+
// lcd.print(" ");
108+
// }
109+
82110
lcd.setCursor(0,1);
83111
for (i = 0; i < length; i++) {
84112
lcd.print((char) payload[i]);

0 commit comments

Comments
 (0)