Created
December 27, 2024 01:29
-
-
Save Innismir/f3d87bd154532e1d6c2d94a0376e8fca to your computer and use it in GitHub Desktop.
Meshtastic Forecast Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import requests, meshtastic, datetime, time, dateutil.parser, syslog | |
| import meshtastic.tcp_interface | |
| def greet_mesh(): | |
| current_time = time.localtime() | |
| hour = current_time.tm_hour | |
| if 5 <= hour < 12: | |
| return "Good morning Mesh!" | |
| elif 12 <= hour < 18: | |
| return "Good afternoon Mesh!" | |
| else: | |
| return "Good evening Mesh!" | |
| def message_broadcast(interface, message): | |
| interface.send(message,'all') | |
| def fetch_forecasts(): | |
| URL = 'https://api.weather.gov/zones/forecast/MAZ020/forecast' | |
| response = requests.get(URL) | |
| return response.json()['properties'] | |
| # Connect to the device | |
| interface = meshtastic.tcp_interface.TCPInterface("192.168.0.1") # Replace with the IP address of your device | |
| forecast = fetch_forecasts() | |
| d = dateutil.parser.parse(forecast['updated']) | |
| time_now = d.strftime('%m/%d/%Y %H:%M %z') | |
| interface.sendText(greet_mesh() + ' Here is the NWS Forecast for Southern Bristol County as of ' + time_now) | |
| time.sleep(3) | |
| interface.sendText(forecast['periods'][0]['name'] + ': ' + forecast['periods'][0]['detailedForecast']) | |
| time.sleep(3) | |
| interface.sendText(forecast['periods'][1]['name'] + ': ' + forecast['periods'][1]['detailedForecast']) | |
| time.sleep(3) | |
| # Close the interface | |
| interface.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment