将数据从PC发送到Android的最佳方式

时间:2013-06-22 13:06:08

标签: android arduino

通过互联网将小字符串从PC发送到Android,从Android发送到PC的最佳方法是什么?

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

1 个答案:

答案 0 :(得分:0)

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

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应用程序,该应用程序从文件中读取值。如果您需要保存所有数据或者想要替换数据,请使用append或其他任何内容。

否则,您只需使用Bluetooth连接即可在设备之间发送串行数据。请参阅 Bluetooth (在ANdroid开发者身上)。

您可能也对 Simple Android and Java Bluetooth Application Data transfer between Android and Arduino via Bluetooth 感兴趣。