Closed ShunjiHashimoto closed 1 year ago
https://teratail.com/questions/311220 subprocess.runはpython3でしか使えない
https://www.richardh.work/entry/2020/03/28/210015 pip3 install RPIO.GPIO
raspiのipアドレス調べ方 https://blog.tkrel.com/8759
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# import rospy
import sys
import time
import RPi.GPIO as GPIO
import lcd_display
import socket
import fcntl
import struct
import subprocess
mylcd = lcd_display.lcd()
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915,
struct.pack('256s', bytes(ifname[:15], 'utf-8'))
)[20:24])
def check_ping():
raspi_ip = get_ip_address('wlan0')
jetson_ip = "192.168.0.104"
hosts = [jetson_ip, raspi_ip]
for host in hosts:
res = subprocess.run(["ping",host,"-c","5", "-W", "1000"],stdout=subprocess.PIPE)
print(res.stdout.decode("cp932"))
print("result:", res.returncode)
print("host: ", host)
if(res.returncode == 0):
return 0
return 1
mylcd.lcd_display_string("ubuntu@raspi", 1)
# check ping
result = 1
while(result != 0):
result = check_ping()
mylcd.lcd_display_string("check ping", 2)
mylcd.lcd_display_string(get_ip_address('wlan0'), 2)
https://shigeblog221.com/python-ping/ 死活監視