From e8dd3c3fe9254cc47f1d8d4656b1725c4222d4c5 Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Wed, 30 Jun 2021 00:56:08 +0100 Subject: [PATCH 1/2] Copy in functioning tests from pi --- .../raspberry_pi/{ => tests}/servo_test.py | 0 .../raspberry_pi/tests/test_i2c.py | 35 +++++++++++++++++++ .../raspberry_pi/tests/test_tx.py | 12 +++++++ 3 files changed, 47 insertions(+) rename crawler_software/raspberry_pi/{ => tests}/servo_test.py (100%) create mode 100644 crawler_software/raspberry_pi/tests/test_i2c.py create mode 100644 crawler_software/raspberry_pi/tests/test_tx.py diff --git a/crawler_software/raspberry_pi/servo_test.py b/crawler_software/raspberry_pi/tests/servo_test.py similarity index 100% rename from crawler_software/raspberry_pi/servo_test.py rename to crawler_software/raspberry_pi/tests/servo_test.py diff --git a/crawler_software/raspberry_pi/tests/test_i2c.py b/crawler_software/raspberry_pi/tests/test_i2c.py new file mode 100644 index 0000000..49c84ca --- /dev/null +++ b/crawler_software/raspberry_pi/tests/test_i2c.py @@ -0,0 +1,35 @@ +# Raspberry Pi Master for Arduino Slave +# i2c_master_pi.py +# Connects to Arduino via I2C + +# DroneBot Workshop 2019 +# https://dronebotworkshop.com + +from smbus import SMBus +import time + +addr = 0x8 # bus address +bus = SMBus(1) # indicates /dev/ic2-1 + +numb = 1 + +print ("Enter num") + +for _x in range (0, 4): + for i in range(70, 130): + bus.write_byte(addr, i) + time.sleep(0.02) + for i in range(130, 70, -1): + bus.write_byte(addr, i) + time.sleep(0.02) + +#while numb == 1: +# +# ledstate = input(">>>> ") +# +# if ledstate == "1": +# bus.write_byte(addr, 0x1) # switch it on +# elif ledstate == "0": +# bus.write_byte(addr, 0x0) # switch it on +# else: +# numb = 0 diff --git a/crawler_software/raspberry_pi/tests/test_tx.py b/crawler_software/raspberry_pi/tests/test_tx.py new file mode 100644 index 0000000..747b9ed --- /dev/null +++ b/crawler_software/raspberry_pi/tests/test_tx.py @@ -0,0 +1,12 @@ +import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library +from time import sleep # Import the sleep function from the time module + +GPIO.setwarnings(False) # Ignore warning for now +GPIO.setmode(GPIO.BOARD) # Use physical pin numbering +GPIO.setup(12, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set initial value to low (off) + +while True: # Run forever + GPIO.output(12, GPIO.HIGH) # Turn on + sleep(1) # Sleep for 1 second + GPIO.output(12, GPIO.LOW) # Turn off + sleep(1) # Sleep for 1 second From 6a74fcb472f6424bcf3d734519b414b9713a08ee Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Wed, 30 Jun 2021 03:19:09 +0100 Subject: [PATCH 2/2] Added crawler discord bot --- .../raspberry_pi/tests/discordbot.py | 61 +++++++++++++++++++ .../raspberry_pi/tests/test_i2c.py | 4 +- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 crawler_software/raspberry_pi/tests/discordbot.py diff --git a/crawler_software/raspberry_pi/tests/discordbot.py b/crawler_software/raspberry_pi/tests/discordbot.py new file mode 100644 index 0000000..02226d4 --- /dev/null +++ b/crawler_software/raspberry_pi/tests/discordbot.py @@ -0,0 +1,61 @@ +from discord_webhook import DiscordWebhook +from picamera import PiCamera +from time import sleep +from gps import * +from smbus import SMBus +import time + +addr = 0x8 # bus address +bus = SMBus(1) # indicates /dev/ic2-1 + +numb = 1 + +try: + for _x in range (0, 2): + for i in range(70, 130): + bus.write_byte(addr, i) + time.sleep(0.02) + for i in range(130, 70, -1): + bus.write_byte(addr, i) + time.sleep(0.02) +except OSError: + print("Could not speak to ardujmemo") + +def get_uptime(): + with open('/proc/uptime', 'r') as f: + uptime_seconds = float(f.readline().split()[0]) + + return uptime_seconds + +def getPositionData(gps): + location = [None] + while(location[0] == None): + print("Trying again") + nx = gpsd.next() + # For a list of all supported classes and fields refer to: + # https://gpsd.gitlab.io/gpsd/gpsd_json.html + if nx['class'] == 'TPV': + latitude = getattr(nx,'lat', "Unknown") + longitude = getattr(nx,'lon', "Unknown") + #print "Your position: lon = " + str(longitude) + ", lat = " + str(latitude) + location = [latitude, longitude] + return location + +gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) + +loc = getPositionData(gpsd) + +webhookURL = "https://discord.com/api/webhooks/856609966404534272/TR9tnLq2sIGZoOeADNswmGRNlzBcqM5aKihfU6snVTP9WhSSoVVvi7nT6i-ZfZS7Hcqm" + +print(loc[0]) +print(loc[1]) +webhook = DiscordWebhook(url=webhookURL, content="Uptime: " + str( round( ((get_uptime() / 60) / 60 ), 2 )) + " hours. Lat is " + str(loc[0]) + ", long is " + str(loc[1])) + +camera = PiCamera() +sleep(3) # let iso settle out +camera.capture('still.jpg') + +with open("still.jpg", "rb") as f: + webhook.add_file(file=f.read(), filename='still.jpg') +response = webhook.execute() # Hit send + diff --git a/crawler_software/raspberry_pi/tests/test_i2c.py b/crawler_software/raspberry_pi/tests/test_i2c.py index 49c84ca..96bf7f3 100644 --- a/crawler_software/raspberry_pi/tests/test_i2c.py +++ b/crawler_software/raspberry_pi/tests/test_i2c.py @@ -16,10 +16,10 @@ numb = 1 print ("Enter num") for _x in range (0, 4): - for i in range(70, 130): + for i in range(76, 130): bus.write_byte(addr, i) time.sleep(0.02) - for i in range(130, 70, -1): + for i in range(130, 76, -1): bus.write_byte(addr, i) time.sleep(0.02)