copied a bunch of shit
parent
fc672e9f81
commit
4b099fb453
@ -1,33 +1,97 @@
|
|||||||
// Rename this file later to main.cpp
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
|
const int deviceId = 0;
|
||||||
|
|
||||||
const char *ssid = "PET Aflytningsvogn #43";
|
const char *ssid = "PET Aflytningsvogn #43";
|
||||||
const char *password = "zwr33htm";
|
const char *password = "zwr33htm";
|
||||||
|
|
||||||
const char *mqtt_server = "192.168.24.215";
|
const char *mqtt_server = "192.168.24.215";
|
||||||
|
|
||||||
const int buzzerPin = D0;
|
WiFiClient espClient;
|
||||||
|
PubSubClient client(espClient);
|
||||||
|
|
||||||
|
int buzzerPin = D0;
|
||||||
int lcdColumns = 16;
|
int lcdColumns = 16;
|
||||||
int lcdRows = 2;
|
int lcdRows = 2;
|
||||||
|
|
||||||
// set LCD address, number of columns and rows
|
|
||||||
LiquidCrystal_I2C lcd(0x3f, lcdColumns, lcdRows);
|
LiquidCrystal_I2C lcd(0x3f, lcdColumns, lcdRows);
|
||||||
|
|
||||||
|
float readADC_Avg(int pin)
|
||||||
|
{
|
||||||
|
float avg = analogRead(pin);
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
avg = (avg + analogRead(pin)) / 2;
|
||||||
|
delay(20);
|
||||||
|
}
|
||||||
|
return avg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_wifi()
|
||||||
|
{
|
||||||
|
delay(10);
|
||||||
|
// We start by connecting to a WiFi network
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("Connecting to ");
|
||||||
|
Serial.println(ssid);
|
||||||
|
|
||||||
|
WiFi.begin(ssid, 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 (client.connect("ESP8266Client"))
|
||||||
|
{
|
||||||
|
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 setup(){
|
void setup(){
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
lcd.init();
|
lcd.init();
|
||||||
lcd.backlight();
|
lcd.backlight();
|
||||||
pinMode(buzzerPin, OUTPUT);
|
pinMode(buzzerPin, OUTPUT);
|
||||||
|
|
||||||
|
setup_wifi();
|
||||||
|
client.setServer(mqtt_server, 1883);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
digitalWrite(buzzerPin, HIGH);
|
// digitalWrite(buzzerPin, HIGH);
|
||||||
lcd.print("Piss off, ghosts!");
|
// lcd.print("Piss off, ghosts!");
|
||||||
delay(1000);
|
// delay(1000);
|
||||||
lcd.clear();
|
// lcd.clear();
|
||||||
digitalWrite(buzzerPin, LOW);
|
// digitalWrite(buzzerPin, LOW);
|
||||||
delay(1000);
|
// delay(1000);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue