Wednesday 30 December 2020

MeteoLeccebot (Telegram Bot)

 Do you now the bot in Telegram, right?

Well, this is my new adventure (in Wi-Fi... cit. one of the album of my favorite band...).

Creating a bot seems to be a simple operation and it is!

So I tried to create ones.

Just for starting I used my best project to transpose it in a Telegram bot answering to the following question: if I wanted to know a specific weather parameter of my weather station? I.e. temperature?

Well: the Telegram bot is the answer! (no, not 42!)

  1. First of all: download Telegram app
  2. Go to the account @BotFather
  3. Create your personal bot through the instructions you find in it
  4. Well... happy hacking!

I chose python to create my personal bot. Take a look at the code, but before of this you have to know that my shield transmits his data to the cloud platform ThingSpeak.com right here: https://thingspeak.com/channels/145284

In this way our bot answer to the request connecting himself to that link and, after analyzed the word received from the user, resend all the main data.

Here is the code:

import sys
import time
import json
from urllib import request
import telepot
from telepot.loop import MessageLoop

def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
print(content_type, chat_type, chat_id, msg)

# immagazzina in una variabile la risposta dal GET response
response = request.urlopen('https://thingspeak.com/channels/145284/feeds.json?results=2')

# preleva i dati json dalla richiesta
data = response.read().decode('utf-8')

# convertiamo la stringa in dizionario
data_dict = json.loads(data)

# separiamo i valori che ci interessano
feeds = data_dict['feeds']

#origin = msg
#origin = msg.read().decode('utf-8')
#data_msg = json.loads(msg)
#dati = data_msg['field1']
#print(msg['text'])

# stampo i valori
text="La Temperatura è di: " + str(float(feeds[1]['field1'])) + " C\n" \
"L'Umidità è il: " + str(float(feeds[1]['field2'])) + " %\n" \
"Il Dew Point è di: " + str(round(float(feeds[1]['field3']),1)) + " C\n" \
"La Pressione è di: " + str(round(float(feeds[1]['field5']),1)) + " hPa"
print(text)

if msg['text'] == 'Meteo' or msg['text'] == 'meteo':
bot.sendMessage(chat_id, text)

#if content_type == 'text':
# bot.sendMessage(chat_id, text)

TOKEN = 'my-token'

bot = telepot.Bot(TOKEN)
MessageLoop(bot, handle).run_as_thread()
print ('Listening ...')

# Keep the program running.
while 1:
time.sleep(10)


Once you access on Telegram you can search for MeteoLeccebot:


And when you ask for the data you have to digit the word Meteo or meteo (weather, in italian) you receive what you have requested:

That's all!


Wednesday 23 December 2020

Weather Station (evolution)

 If I can free more space in the box that contains all the components of the weather station: welcome!

I can do it using a component which contains a lot of sensors in itself. the BME280.

This electronic component is a multisensor, it can measure:

  • Temperature
  • Humidity
  • Atmosferic pressure

BME280
 

I bought it here:

BME280

 

  That's all... then... start again projecting a new device!

Saturday 12 December 2020

Drawing a neuron for fun

Have fun drawing the topics you are reading...

Meet the Artemis Team

Could I not think about the Moon and the next missions?

Obviously no... thus... Artemis is the next generation that will step on it: have a good take off, a good travel and ...send back the best message: united towards the civilization of other planets in the name of peace!

Monday 16 November 2020

Computer science TV series

 If you want be absorbed by a story I suggest you to watch this TV series:

STALK

Happy hacking!