-
The Rube Goldberg Website Button
08/02/2018 at 16:06 • 0 comments***Edit to use the website buttons, the Atltvhead must be on, I live stream every Friday 6pm Est.
Oh man! What I am about to share with you is not the best example of coding, making, communicating, but it works!
Here is a photo from my mobile site and buttons:
Design intent: give non twitch users ability to change the screen
-buttons on my website (not a mobile app)
-literally zero changes to the atltvhead microcontroller code
-must work with Wix we site
-must work with me existing Twitch.tv interface/api
Process Flow:
Wix Javascript -> Google Api Python (email)-> Twitch Api Python -> Twitch API C++ (Atltvhead)
Build Out: Wix
Since my website is hosted on Wix, and I didn't want to buy a home server to host my website and possible open my networks firewall, I had to figure out a way to send out button presses.
Wix Code is a relatively new way to intereact and design for Wix websites. See the photo below.
This Javascript based side of the websites allows for button presses to trigger lines of code. It also allows for the addition of website users from the back end.
For my website, I was able to make these button presses send a premade email. The subject of the email changes for each button. The email address and particular subject lines will be read with a Python script in the next section. Below is the code from my wix site.
import wixCRM from 'wix-crm'; import wixUsers from 'wix-users'; //... export function ButtonOnPress(event, $w) { //Add your code for this event here: wixCRM.createContact({ "emails":['Your_Email_Here'] }) .then((contactId)=>{ wixCRM.emailContact('Pre_Made_Wix_Email_Here',contactId, { variables: { command: 'Subject_Here' }}) .catch( (err) => { console.log(err) }); }); }
Build Out: Python Script
To use this script you will have to follow Google's Python API getting started guide and give permission to modify emails. You will need a Google email account, and a twitch account for the chatbot to function.
How this Python script functions by constantly reading the unread emails in an inbox. When a particular subject is found it sends a message to the twitch server, putting text command into the chat of a particular streamer. It finishes by marking that email read and continuing to read the unread messages in the inbox.
Find more info for the Google side here and Twitch side here!
""" Shows basic usage of the Gmail API. Lists the user's Gmail labels. """ from apiclient import discovery from apiclient import errors from httplib2 import Http from oauth2client import file, client, tools import base64 import cfg #configure file with Twitch account, Aouth password, and which stream chat you are going to import socket import re import time import multiprocessing def chat(sock, msg): """ Send a chat message to the server. Keyword arguments: sock -- the socket over which to send the message msg -- the message to be sent """ sock.send("PRIVMSG {} :{}\r\n".format(cfg.CHAN, msg).encode("utf-8")) s = socket.socket() s.connect((cfg.HOST,cfg.PORT)) s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8")) s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8")) s.send("JOIN {}\r\n".format(cfg.CHAN).encode("utf-8")) CHAT_MSG=re.compile(r"^:\w+!\w+@\w+.tmi.twitch.tv PRIVMSG #\w+ :") # Setup the Gmail API SCOPES = 'https://www.googleapis.com/auth/gmail.modify' # we are using modify and not readonly, as we will be marking the messages Read store = file.Storage('storage.json') creds = store.get() if not creds or creds.invalid: flow = client.flow_from_clientsecrets('client_secret.json', SCOPES) creds = tools.run_flow(flow, store) service = discovery.build('gmail', 'v1', http=creds.authorize(Http())) user_id = 'me' label_id_one = 'INBOX' label_id_two = 'UNREAD' #gets all of the unread messages from the inbox def remail(): while True: unread_msgs = service.users().messages().list(userId='me',labelIds=[label_id_two]).execute() mess = unread_msgs['messages'] final_list=[] #print ("Total messaged retrived: ", str(len(mess))) for msgs in mess: temp_dict = { } m_id = msgs['id'] message = service.users().messages().get(userId=user_id, id=m_id).execute() #get message using api payId=message['payload'] headr =payId['headers'] for one in headr: if one['name'] == 'Subject': msg_subject = one['value'] temp_dict['Subject']= msg_subject else: pass for three in headr: if three['name']=='From': msg_from = three['value'] temp_dict['Sender']= msg_from else: pass #print(temp_dict['Subject']) #print(temp_dict['Sender']) if temp_dict['Subject'] == 'Email_Subject_1': chat(s,"Chat_Command_1") service.users().messages().modify(userId=user_id, id=m_id, body={ 'removeLabelIds': ['UNREAD']}).execute() elif temp_dict['Subject'] == 'Email_Subject_2': chat(s,"Chat_Command_2") service.users().messages().modify(userId=user_id, id=m_id, body={ 'removeLabelIds': ['UNREAD']}).execute() time.sleep(1 / cfg.RATE) def pingPong(): while True: response = s.recv(1024).decode("utf-8") if response == "PING :tmi.twitch.tv\r\n": s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8")) time.sleep(1 / cfg.RATE) if __name__ == '__main__' : p = multiprocessing.Process(target=pingPong) m = multiprocessing.Process(target=remail) p.start() m.start()
-
First Stream HyperSpeed!
07/30/2018 at 16:35 • 0 commentsJust wanted to give N update! I was able to finish the new atltvhead screen controls onto my website!
I'll be documenting the process in detail soon. It is quite the Rube Goldberg of code, running through Wix code, to Google API, and finishing at Twitch API. All in an effort to keep my household behind a firewall. It runs in a combo of Java Script and Python.
Also I am editing the video from a stream on July 27th. I had a good amount of twitch chat to city goer interaction! Thanks to @theotherlonestar, oooKaylie, and Alex Atkins!
To finish off, here is a short video of the stream on Friday, July 20th.
-
Starting to Give "Offline" People Tvhead Controls
07/16/2018 at 19:36 • 0 commentsWhile walking with the tvhead on for the past few weeks, I've been thinking more about how people can interact with the tv controls in person. There are ways for chat to control it, but how do I give someone in front of me access to the same interaction/play.
I am working on a way to add a few buttons to control the animations from my website, while still going through the Twitch chatbot API. This will give some amount of chatbot control to people without a twitch account. It's weird but the bot will become a limited way for people in life to interact back with chat, as much as chat can interact through the tv. I'll be playing with how the interaction should play out. If "offline" people will give suggestions for chat to help with or if they should have direct control like other chat members.
Just wanted to give everyone a note as to the progress and what I am currently working on.
STREAMING SCHEDULE
Every Friday 6pm est, I'll be streaming and walking in the city! So come on out (online) and control Atltvhead!
-
Some New Video's About Controlling the tv Screen!
06/15/2018 at 14:53 • 0 comments -
Hackaday Prize Submission!
04/24/2018 at 00:24 • 0 comments -
Model A's (Tiny Tv's)
03/07/2018 at 23:18 • 0 commentsSo I ended up making a few small retro tv's recently. They'll get their own project at some point but for now they are the Atltvhead's tv's.
-
Chat Commands for inside Twitch
01/17/2018 at 23:18 • 0 commentsCurrently I am working on more animation's and modifiers to the Tv Control.
The chat commands can either trigger a chat bot command or a tv modification. Below are the chat commands for the bot. The chat bot is always on, feel free to type any of these in the chat at Twitch or my own site.!hug : Chat command, Tvheadbot gives you a virtual hug
!love : Chat command, Tvheadbot shares some love your way
!goodvibes : Chat command, Tvheadbot shares some words of positivity with you
!goals : Chat command, Tvheadbot lets you know what the community goals are
!howtoshare : Chat command, Tvheadbot lets you know how to contribute community goals, or positivity
!help : Chat command, Tvheadbot lets you know what the chat commands are
!tvbot : Chat command, Tvheadbot lets you know what it is
!atltvhead : Chat command, Tvheadbot lets you know who atltvhead is