This article mainly introduces in detail how .Net Core uses Socket to communicate with Raspberry Pi. It has certain reference value. Interested friends can refer to it
Preface
The Raspberry Pi I bought last year has been sitting in a drawer gathering dust. Debian 9 was released a while ago, and not surprisingly, it supports the Raspberry Pi.
So I took out the card reader again and installed the Debian desktop system again.
Introduction
The current level of this thing is just to understand the communication between Python and .Net. The best version should be that Raspberry Pi commands can be executed remotely through the server.
Everyone knows the reason for this. Many broadbands do not provide external network IP. This means that the family does not have a public network IP, and there is no way to remotely control the Raspberry Pi. What I want to do is similar to the internal network. Penetrating Ngrok and the like.
Effect
Python side
#!/usr/bin/env python2 #-*- coding: utf-8 -*- import socket import threading import os host = '192.168.31.7' port = 5001 s = 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()
Very simple code Snippet, I should be able to write a rough prototype by this time next week. This is now on the server to test the stability of the server side.
The above is the detailed content of Detailed explanation of .Net Core using Socket to communicate with Raspberry Pi. For more information, please follow other related articles on the PHP Chinese website!