ShunjiHashimoto / tang

収穫サポートロボットTANG
2 stars 1 forks source link

起動後のraspi.jetsonの疎通確認 #210

Closed ShunjiHashimoto closed 1 year ago

ShunjiHashimoto commented 2 years ago

https://shigeblog221.com/python-ping/ 死活監視

ShunjiHashimoto commented 2 years ago

https://teratail.com/questions/311220 subprocess.runはpython3でしか使えない

ShunjiHashimoto commented 2 years ago

https://www.richardh.work/entry/2020/03/28/210015 pip3 install RPIO.GPIO

ShunjiHashimoto commented 2 years ago

raspiのipアドレス調べ方 https://blog.tkrel.com/8759

ShunjiHashimoto commented 2 years ago

参考になるかも https://ja.stackoverflow.com/questions/59457/arp-scan%E3%81%A7%E5%8F%96%E5%BE%97%E3%81%97%E3%81%9Fip%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E3%81%B8%E4%B8%80%E6%96%89%E3%81%ABping%E3%82%92%E9%80%81%E3%82%8A%E3%81%9F%E3%81%84

https://www.haljion.net/index.php/2019-11-13-03-27-18/2019-11-13-11-33-14/129-raspberry-pi/trouble-shooting/251-raspberrypi-local

ShunjiHashimoto commented 2 years ago

#!/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)