2020-11-21 21:21:26 +01:00
|
|
|
/*
|
|
|
|
Copyright (c):
|
|
|
|
|
|
|
|
Philipp Matthias Schäfer (philipp.matthias.schaefer@posteo.de), 2020
|
|
|
|
|
|
|
|
This file is part of the KrautStatus' Arduino code.
|
|
|
|
|
|
|
|
The Clean CommonMark library is free software: you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
The Clean CommonMark library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License along
|
|
|
|
with the Clean CommonMark library. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-11-18 22:45:14 +01:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <WiFi101.h>
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
WiFiUDP Udp;
|
|
|
|
|
2020-12-11 14:18:46 +01:00
|
|
|
void print_mac_address() {
|
|
|
|
uint8_t mac[6];
|
|
|
|
WiFi.macAddress(mac);
|
|
|
|
Serial.print("MAC: ");
|
|
|
|
for(unsigned int i = 5; i > 0; --i) {
|
|
|
|
Serial.print(mac[i], HEX);
|
|
|
|
Serial.print(":");
|
|
|
|
}
|
|
|
|
Serial.println(mac[0], HEX);
|
|
|
|
}
|
2020-11-18 22:45:14 +01:00
|
|
|
|
2020-12-11 14:18:46 +01:00
|
|
|
boolean wifi_setup() {
|
2020-11-18 22:45:14 +01:00
|
|
|
if (WiFi.status() == WL_NO_SHIELD) {
|
|
|
|
Serial.println("No WiFI shield present");
|
2020-12-11 14:18:46 +01:00
|
|
|
return false;
|
2020-11-18 22:45:14 +01:00
|
|
|
}
|
|
|
|
|
2020-12-11 14:18:46 +01:00
|
|
|
print_mac_address();
|
|
|
|
|
2020-11-18 22:45:14 +01:00
|
|
|
while (true) {
|
|
|
|
Serial.print("Connecting to SSID: ");
|
|
|
|
Serial.println(SSID);
|
|
|
|
|
2020-12-11 14:18:46 +01:00
|
|
|
if (WiFi.begin(SSID, PASSWORD) == WL_CONNECTED) {
|
2020-11-18 22:45:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(10000);
|
|
|
|
}
|
|
|
|
|
2020-12-11 14:18:46 +01:00
|
|
|
Serial.println("Connect to WiFi");
|
2020-11-18 22:45:14 +01:00
|
|
|
Serial.print("IP Address: ");
|
2020-12-11 14:18:46 +01:00
|
|
|
Serial.println(WiFi.localIP());
|
2020-11-18 22:45:14 +01:00
|
|
|
|
2020-12-11 14:18:46 +01:00
|
|
|
Udp.begin(SERVER_PORT);
|
2020-11-18 22:45:14 +01:00
|
|
|
|
2020-12-11 14:18:46 +01:00
|
|
|
return true;
|
2020-11-18 22:45:14 +01:00
|
|
|
}
|