. NET core uses sockets to communicate with the Raspberry Pi Example analysis (graphic)

Source: Internet
Author: User

Objective

Last year's Raspberry Pi has been in the drawer to eat ash, the previous array of Debian 9 released, there is no accidental support for the Raspberry Pi.

Then re-took out the card reader and re-installed on the Debian Desktop version of the system.

Introduced

Now this thing is just a little bit more about Python and. NET communication. The best version should be that the Raspberry Pi command can be executed remotely from the server side.

The reasons for doing so we all know, many broadband now do not provide an external network IP, so that the family does not have a public IP, there is no way to remote control of the Raspberry Pi, I want to do something similar to the intranet penetrate Ngrok and the like.

Effect

Python side


#!/usr/bin/env python2#-*-coding:utf-8-*-import socketimport threadingimport oshost = ' 192.168.31.7 ' port = 5001s = Sock Et.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 () def getcputemperature ():    res = Os.popen (' Vcgencmd measure_temp '). ReadLine ()    return ( Res.replace ("temp=", "" "). Replace (" ' c\n "," ")) if __name__ = = ' __main__ ':    Start ()

Very simple code snippet, this time next week should be able to write the approximate prototype, this server now test the stability of the server side.

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.