. Net Core uses Socket to communicate with Raspberry Pi for details, coresocket

Source: Internet
Author: User

. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.