[PYTHON] I made you to express the end of the IP address with L Chika

download

Commentary

Video

If the IP address is 192.168.0.156, get the last 156. 156 is expressed by LED character by character as follows.

Usage

sudo lastip.py

code

lastip.py


import socket
import time

def get_my_ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("gmail.com",80))
    ipaddr = s.getsockname()[0]
    s.close()
    return ipaddr

def write(filename, str):
    f = open(filename, 'w')
    f.write(str)
    f.close()

class LED:
    def __init__(self, num):
        self.name = '/sys/class/leds/led'+str(num)
        self.trigger = self.name + '/trigger'
        self.brightness = self.name + '/brightness'
        self.delay_on = self.name + '/delay_on'
        self.shot = self.name + '/shot'
    def on(self):
        write(self.trigger, 'none')
        write(self.brightness, '1')
    def off(self):
        write(self.trigger, 'none')
        write(self.brightness, '0')
    def heartbeat(self):
        write(self.trigger, 'heartbeat')
    def oneshot(self, second):
        write(self.trigger, 'oneshot')
        write(self.delay_on, str(second))
        write(self.shot, '1')

def num2led(num, led0, led1):
    led1.on()
    for var in range(0, num):
        led0.oneshot(200) #ms
        time.sleep(0.25)
        led0.off()
    led1.off()
    time.sleep(1)

if __name__ == '__main__':
    led0 = LED(0)
    led1 = LED(1)
    ipaddr = get_my_ip()
    ipaddr_last = ipaddr.split(".")[3]
    for num in list(ipaddr_last):
        num2led(int(num), led0, led1)

Recommended Posts

I made you to express the end of the IP address with L Chika
I want to express my feelings with the lyrics of Mr. Children
I tried to visualize the text of the novel "Weathering with You" with WordCloud
Coordinates of the right end of Label made with tkinter
I wrote you to watch the signal with Go
I tried to find the entropy of the image with python
I tried to analyze the whole novel "Weathering with You" ☔️
I tried to find the average of the sequence with TensorFlow
I made a function to check the model of DCGAN
When you access the web server, L Chika with Arduino
I tried to automate the watering of the planter with Raspberry Pi
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I want to output the beginning of the next month with Python
I tried to expand the size of the logical volume with LVM
I want to check the position of my face with OpenCV!
I tried to improve the efficiency of daily work with Python
How to display the CPU usage, pod name, and IP address of a pod created with Kubernetes
I tried to express sadness and joy with the stable marriage problem.
[Django] I made a field to enter the date with 4 digit numbers
I tried to get the authentication code of Qiita API with Python.
I tried to automatically extract the movements of PES players with software
Try to react only the carbon at the end of the chain with SMARTS
Allow Slack to notify you of the end of a time-consuming program process
I tried to analyze the negativeness of Nono Morikubo. [Compare with Posipa]
I made a GAN with Keras, so I made a video of the learning process.
I tried to streamline the standard role of new employees with Python
When you access the web server, L Chika (HTTPS compatible) with Arduino
I want to stop the automatic deletion of the tmp area with RHEL7
I tried to get the movie information of TMDb API with Python
I made a program to check the size of a file in Python
I made a mistake in fetching the hierarchy with MultiIndex of pandas
I made an npm package to get the ID of the IC card with Raspberry Pi and PaSoRi
I tried to predict the behavior of the new coronavirus with the SEIR model.
I made a function to see the movement of a two-dimensional array (Python)
I made a tool to estimate the execution time of cron (+ PyPI debut)
The story of IPv6 address that I want to keep at a minimum
I failed to install django with pip, so a reminder of the solution
Specify the start and end positions of files to be included with qiitap
I made an appdo command to execute a command in the context of the app
With LINEBot, I made an app that informs me of the "bus time"
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
What you want to memorize with the basic "string manipulation" grammar of python
Linux: Netplan configuration guide to see when you want to fix the IP address
I made a tool to automatically back up the metadata of the Salesforce organization
I made a script to record the active window using win32gui of Python
The story of making soracom_exporter (I tried to monitor SORACOM Air with Prometheus)
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to automatically send the literature of the new coronavirus to LINE with Python
Note to plot IP address with Kibana + Elasticsearch
I tried to save the data with discord
I wanted to play with the Bezier curve
I tried to touch the API of ebay
I tried to correct the keystone of the image
I want to use ip vrf with SONiC
I want to customize the appearance of zabbix
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to make the weather forecast on the official line by referring to the weather forecast bot of "Dialogue system made with python".
I made a twitter app that decodes the characters of Pricone with heroku (failure)
[Python] I made an app to practice the subtle voice distinction of English words.
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow