-1

通过 Internet 从 PC 到 Android 以及从 Android 到 PC 发送小字符串的最佳方式是什么?

我有一个 Arduino,它从两个传感器读取温度值并将它们发送到VB.NET应用程序。我想创建一个 Android 应用程序,通过 Internet 读取这些值并将它们显示在我的智能手机屏幕上。是否有任何指南通过HTTP或类似的方式发送小字符串?我想要一个非常简单的指南。尽可能简单,因为我是初学者。

4

1 回答 1

0

您可以使用Python使用POST将数据从计算机发送到 Web 服务器:

import urllib2, urllib
mydata = [('one','1')]    #The first is the var name the second is the value
mydata = urllib.urlencode(mydata)
path = 'http://localhost/new.php'    #The URL you want to POST to
req = urllib2.Request(path, mydata)
req.add_header("Content-type", "application/x-www-form-urlencoded")
page = urllib2.urlopen(req).read()
print page

使用PHP将它们写入服务器上的文件:

<?php
    $file = "path/to/file/here" ;
    file_put_contents($file, $_POST['one'], FILE_APPEND | LOCK_EX);
?>

现在开发从文件中读取值的 Android 应用程序。如果您需要保存所有数据或想要替换数据,请使用追加或其他方式。

否则,您可以只使用蓝牙连接在设备之间发送串行数据。请参阅蓝牙(在 Android 开发人员上)。

您可能还对简单的 Android 和 Java 蓝牙应用程序以及通过蓝牙在 Android 和 Arduino 之间传输数据感兴趣。

于 2013-06-22T13:51:53.683 回答