前言去年买的树莓派一直放在抽屉里吃灰,前些阵子debian 9发布,也不出意外的支持了树莓派。
于是重新拿出读卡器又重新了装上了debian桌面版系统。
介绍现在这个东西目前的程度只是了解一下python和.net的通信。最佳的版本应该是,可以通过服务器端远程执行树莓派命令。
这样做的原因大家也都知道,很多宽带现在不提供外网ip,这样造成家庭没有公网ip,也没办法远程对树莓派控制,我想做的东西类似内网穿透ngrok之类的。
效果
python端
#!/usr/bin/env python2
#-*- coding: utf-8 -*-import socket
import threading
import os
host = '192.168.31.7'port = 5001s = socket.socket(socket.af_inet, socket.sock_stream)
s.connect((host, port))
def start():
a = 0
while true:
a = a+1
data = str(a).encode('utf8') + getcputemperature().encode('utf8')
#s.send(str(a).encode('utf8'))
print(data)
#print(data)
threading._sleep(10)
def getcputemperature():
res = os.popen('vcgencmd measure_temp').readline() return(res.replace("temp=","").replace("'c\n",""))if __name__ == '__main__':
start()
很简单的代码片段,下星期的这时候应该就能写出大概的原型了,这个现在服务器上测试一下服务器端的稳定性。
以上就是.net中core使用socket与树莓派进行通信的实例分析(图文)的详细内容。