Home  >  Article  >  Backend Development  >  Example analysis of Core using Socket to communicate with Raspberry Pi in .Net (picture and text)

Example analysis of Core using Socket to communicate with Raspberry Pi in .Net (picture and text)

黄舟
黄舟Original
2017-09-18 11:28:561888browse

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 = 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()

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 Example analysis of Core using Socket to communicate with Raspberry Pi in .Net (picture and text). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn