. Net Core uses Socket to communicate with Raspberry Pi for details, coresocket
Preface
Last year, I bought Raspberry Pi, which had been put in a drawer for gray purposes. A few days ago, Debian 9 was released, and I was not surprised to support Raspberry Pi.
So I took out the card reader and installed the Debian desktop system again.
Introduction
At present, this is only about the communication between Python and. Net. The best version is to remotely execute Raspberry Pi commands on the server.
The reason for doing so is that many broadband networks do not provide Internet IP addresses. As a result, families do not have public ip addresses and cannot remotely control Raspberry Pi, I want to do something like Intranet penetration Ngrok.
Effect
Python end
#!/usr/bin/env python2#-*- coding: utf-8 -*-import socketimport threadingimport oshost = '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()
The simple code snippet should be able to write a rough prototype next week. Now we can test the server stability on the server.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.