Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用手机将raspberry pi连接到Wifi_Php_Python_Linux_Raspberry Pi_Raspberry Pi2 - Fatal编程技术网

Php 使用手机将raspberry pi连接到Wifi

Php 使用手机将raspberry pi连接到Wifi,php,python,linux,raspberry-pi,raspberry-pi2,Php,Python,Linux,Raspberry Pi,Raspberry Pi2,我用的是覆盆子皮2模型B 我想通过手机将我的raspberry pi连接到检测到的wifi网络 在使用手机连接到raspberry pi后,我可以通过在url中输入ip地址来访问raspberry pi的web服务器 我目前能够在raspberry pi的web服务器上扫描检测到的wifi,如所示: 以及: 用于扫描wifi的Python代码: #!/usr/bin/env python import subprocess import re class line_matcher:

我用的是覆盆子皮2模型B

我想通过手机将我的raspberry pi连接到检测到的wifi网络

在使用手机连接到raspberry pi后,我可以通过在url中输入ip地址来访问raspberry pi的web服务器

我目前能够在raspberry pi的web服务器上扫描检测到的wifi,如所示:

以及:

用于扫描wifi的Python代码:

#!/usr/bin/env python
import subprocess
import re

class line_matcher:
    def _init_(self, regexp, handler):
        self.regexp  = re.compile(regexp)
        self.handler = handler


def handle_new_network(line, result, networks):
# group(1) is the mac address
networks.append({})
networks[-1]['Address'] = result.group(1)

def handle_essid(line, result, networks):
    # group(1) is the essid name
    networks[-1]['ESSID'] = result.group(1)

def handle_quality(line, result, networks):
    # group(1) is the quality value
    # group(2) is probably always 100
    networks[-1]['Quality'] = result.group(1) + '/' + result.group(2)

def handle_unknown(line, result, networks):
    # group(1) is the key, group(2) is the rest of the line
    networks[-1][result.group(1)] = result.group(2)

if _name_ == '_main_':
    proc = subprocess.Popen(['/sbin/iwlist', 'wlan0', 'scan'],
                            stdout=subprocess.PIPE)
    stdout, stderr =  proc.communicate()

    lines = stdout.split('\n')

    networks = []
    matchers = []

    # catch the line 'Cell ## - Address: XX:YY:ZZ:AA:BB:CC'
    matchers.append(line_matcher(r'\s+Cell \d+ - Address: (\S+)',
                                 handle_new_network))

    # catch the line 'ESSID:"network name"
    matchers.append(line_matcher(r'\s+ESSID:"([^"]+)"', 
                                 handle_essid))

    # catch the line 'Quality:X/Y Signal level:X dBm Noise level:Y dBm'
    #matchers.append(line_matcher(r'\s+Quality:(\d+)/(\d+)',
                                 #handle_quality))

    # catch any other line that looks like this:
    # Key:value
    matchers.append(line_matcher(r'\s+([^:]+):(.+)',
                                 handle_unknown))

    # read each line of output, testing against the matches above
    # in that order (so that the key:value matcher will be tried last)
    for line in lines:
        for m in matchers:
            result = m.regexp.match(line)
            if result:
                m.handler(line, result, networks)
                break

    for n in networks:
        x= 'Found network', n['ESSID']
        print x
        # to see the whole dictionary:
        # print n
HTML代码:

<html>

<head>

<title>My Python Website!</title>
</head>

<body>

    <h1><font size="6" color="red" face="verdana">Welcome to my Python-based website!</font></h1>

    <p><b><i><font size="3" color="gray" face="verdana">This is my first Python-based website that is running on my Raspberry Pi!</font></i></b></p>
    <form action="index.php" method="post">
    <input type="submit" value="Scan"/>
    </form>
    </body>

    </html>

我的Python网站!
欢迎访问我的基于Python的网站!
这是我的第一个基于Python的网站,运行在我的Raspberry Pi上

PHP代码:

<?php
$output=shell_exec('/usr/bin/python test2.py');
print($output)

?>


您的问题出在哪里?请尽可能详细说明(错误消息、操作等)嗨,我想用手机通过接入点连接到树莓Pi。然后在我的手机浏览器上输入Raspberry Pi的ip地址,对可用网络进行简单扫描(python),并允许用户根据扫描的可用网络选择并连接到选定的网络。我在允许用户选择扫描的可用网络,然后将Raspberry Pi设置为从手机连接到所选网络时遇到问题。不清楚您的问题是什么。你应该在问题中清楚地说明这一点。这可能很有用:。你有什么问题?请尽可能详细说明(错误消息、操作等)嗨,我想用手机通过接入点连接到树莓Pi。然后在我的手机浏览器上输入Raspberry Pi的ip地址,对可用网络进行简单扫描(python),并允许用户根据扫描的可用网络选择并连接到选定的网络。我在允许用户选择扫描的可用网络,然后将Raspberry Pi设置为从手机连接到所选网络时遇到问题。不清楚您的问题是什么。你应该在问题中清楚地说明这一点。这可能有用:。