Окт 282013
 

Узнаем IP address который получила pcDuino через DHCP и посылаем его в Arduino через UART.

#!/usr/bin/env python

import socket
import fcntl
import struct
import serial
import time, os

def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])

# Инициализация порта UART0

def uart_init():
    GPIO_MODE_PATH= os.path.normpath('/sys/devices/virtual/misc/gpio/mode/')
    GPIO_PIN_PATH=os.path.normpath('/sys/devices/virtual/misc/gpio/pin/')
    GPIO_FILENAME="gpio"

    pinMode = []
    pinData = []

    SERIAL = "3"

    for i in range(0,2):
	pinMode.append(os.path.join(GPIO_MODE_PATH, 'gpio'+str(i)))
        pinData.append(os.path.join(GPIO_PIN_PATH, 'gpio'+str(i)))

    file = open(pinMode[0], 'r+')
    file.write(SERIAL)
    file.close()
    file = open(pinMode[1], 'r+')
    file.write(SERIAL)
    file.close()

uart_init()

pcDuinoIPaddress = get_ip_address('wlan0')

arduino = serial.Serial('/dev/ttyS1',baudrate=115200,timeout=10)

arduino.write("["+pcDuinoIPaddress+"]")

arduino.close()

 Posted by at 03:43

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*