-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
worker: python3 susmabot.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-3.10.6 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include <Adafruit_GFX.h> | ||
#include <Adafruit_SSD1306.h> | ||
#include <SoftwareSerial.h> | ||
#define SCREEN_WIDTH 128 | ||
#define SCREEN_HEIGHT 32 | ||
#define OLED_RESET -1 | ||
#define SCREEN_ADDRESS 0x3C | ||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); | ||
|
||
String networkID = ""; | ||
String networkPass = ""; | ||
|
||
int rxPin = 10; | ||
int txPin = 11; | ||
|
||
String thingSpeakIPAddress = "184.106.153.149"; | ||
|
||
SoftwareSerial esp(rxPin, txPin); | ||
|
||
int resval = 0; | ||
int respin = A3; | ||
|
||
unsigned long prevMillis = 0; | ||
const long interval = 1000; | ||
|
||
void setup() | ||
{ | ||
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { | ||
for (;;); | ||
} | ||
|
||
display.clearDisplay(); | ||
draw(false); | ||
|
||
esp.begin(115200); | ||
esp.println("AT"); | ||
|
||
while (!esp.find("OK")) | ||
{ | ||
esp.println("AT"); | ||
} | ||
|
||
esp.println("AT+CWMODE=1"); | ||
|
||
while (!esp.find("OK")) | ||
{ | ||
esp.println("AT+CWMODE=1"); | ||
} | ||
|
||
esp.println("AT+CWJAP=\"" + networkID + "\",\"" + networkPass + "\""); | ||
|
||
while (!esp.find("OK")); | ||
|
||
delay(1000); | ||
} | ||
|
||
void loop() | ||
{ | ||
draw(true); | ||
|
||
esp.println("AT+CIPSTART=\"TCP\",\"" + thingSpeakIPAddress + "\",80"); | ||
|
||
String thingSpeakData = ""; | ||
|
||
unsigned long currentMillis = millis(); | ||
|
||
if (currentMillis - prevMillis >= interval) | ||
{ | ||
prevMillis = currentMillis; | ||
|
||
resval = analogRead(respin); | ||
|
||
display.clearDisplay(); | ||
display.setTextSize(2); | ||
display.setTextColor(SSD1306_WHITE); | ||
display.setCursor(0, 0); | ||
display.cp437(true); | ||
display.print("Res value is: "); | ||
display.println(resval); | ||
display.display(); | ||
|
||
thingSpeakData += String(resval); | ||
thingSpeakData += "\r\n\r\n"; | ||
|
||
esp.print("AT+CIPSEND="); | ||
esp.println(thingSpeakData.length() + 2); | ||
delay(2000); | ||
|
||
if (esp.find(">")) | ||
{ | ||
esp.print(thingSpeakData); | ||
delay(1000); | ||
} | ||
|
||
esp.println("AT+CIPCLOSE"); | ||
delay(1000); | ||
} | ||
} | ||
|
||
void draw(bool status) | ||
{ | ||
display.clearDisplay(); | ||
display.setTextSize(2); | ||
display.setTextColor(SSD1306_WHITE); | ||
display.setCursor(0, 0); | ||
display.cp437(true); | ||
|
||
if (status) | ||
display.write("Detection is ON!"); | ||
else | ||
display.write("Detection is OFF!"); | ||
|
||
display.display(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
import random | ||
import discord | ||
import glob | ||
import requests | ||
from discord.ext import commands | ||
from discord.ext import tasks | ||
from dotenv import load_dotenv | ||
|
||
images = [] | ||
for filename in glob.glob('pics/*.jpg'): | ||
images.append(filename) | ||
|
||
load_dotenv() | ||
TOKEN = os.getenv('DISCORD_TOKEN') | ||
GUILD = os.getenv('DISCORD_GUILD') | ||
|
||
intents = discord.Intents.all() | ||
intents.members = True | ||
|
||
help_command = commands.DefaultHelpCommand( | ||
no_category = 'Commands' | ||
) | ||
|
||
bot = commands.Bot(command_prefix = '!', intents = intents, help_command = help_command) | ||
|
||
lastEntryDate = None | ||
|
||
def checkWaterLevel(): | ||
msg = requests.get("") | ||
date = msg.json()['feeds'][-1]['created_at'] | ||
msg = msg.json()['feeds'][-1]['field1'] | ||
|
||
return int(msg), date | ||
|
||
@bot.command(help = "Woof woof istiyosan woofla!") | ||
async def woof(ctx): | ||
response = "Woof woof!" | ||
await ctx.send(response) | ||
|
||
@bot.command(help = "Su seviyesi için su woof woofla!") | ||
async def water(ctx): | ||
response = "Su seviyesi için su woof woofla!" | ||
await ctx.send(response) | ||
|
||
@bot.command(help = "Susma foto için susmaVre!") | ||
async def susmaVre(ctx): | ||
response = discord.File(images[random.randrange(0, len(images))]) | ||
await ctx.send(file = response) | ||
response = response.filename | ||
await ctx.send(response.split('.', 1)[0]) | ||
|
||
@bot.event | ||
async def on_ready(): | ||
await checkWaterLevelTask.start() | ||
await bot.change_presence(activity = discord.Activity(type = discord.ActivityType.playing, name = "Woof woof!")) | ||
|
||
@bot.event | ||
async def on_message(message): | ||
if message.author == bot.user: | ||
return | ||
|
||
if message.content == "Su" or message.content == "su" or message.content == "SU": | ||
response = format(message.author.mention) + ", su seviyesi " + str(checkWaterLevel()[0]) | ||
await message.channel.send(response) | ||
|
||
if message.content == "Woof" or message.content == "woof" or message.content == "havla" or message.content == "Havla": | ||
response = "Woof woof!" | ||
await message.channel.send(response) | ||
|
||
await bot.process_commands(message) | ||
|
||
@tasks.loop(minutes = 10) | ||
async def checkWaterLevelTask(): | ||
global lastEntryDate | ||
if checkWaterLevel()[0] < 300 and checkWaterLevel()[1] != lastEntryDate: | ||
lastEntryDate = checkWaterLevel()[1] | ||
channel = bot.get_channel() | ||
await channel.send("Woof susadım woof!") | ||
|
||
if __name__ == '__main__': | ||
bot.run(TOKEN) |