Microsoft MVP성태의 닷넷 이야기
사물인터넷: 48. 넷두이노의 C# 네트워크 프로그램 [링크 복사], [링크+제목 복사],
조회: 21400
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

넷두이노의 C# 네트워크 프로그램

(이제는 너무 오래된) 넷두이노 모델 중 "Netduino Plus" 모델은,

넷두이노(Netduino)의 네트워크 설정 방법
; https://www.sysnet.pe.kr/2/0/11702

유선 랜을 지원합니다. 반면 최근 넷두이노 제품을 보면,

Netduino
; https://www.wildernesslabs.co/netduino

이더넷과 와이파이 모델을 모두 판매하고 있는데 대략 각각 $45, $50에 구매할 수 있습니다. 다른 아두이노 호환 모델과 비교해 이 보드의 장점이 있다면... 바로 개발이 무척 쉽다는 점입니다. 어느 정도로 쉽냐면??? 심지어 네트워크의 경우 HttpWebRequest 타입까지도 지원하기 때문에 거의 데스크톱 경험으로 개발할 수 있습니다. 일례로, 다음의 코드는 웹 페이지를 읽어오면 LED를 켜는 기능을 구현하고 있습니다.

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.IO;
using System.Text;
using Microsoft.SPOT.Net.NetworkInformation;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace NetworkLED
{
    public class Program
    {
        static byte[] _contentBuffer = new byte[1024];

        public static void Main()
        {
            OutputPort led7 = new OutputPort(Pins.ONBOARD_LED, false);
            EnableNetwork();

            while (true)
            {
                string txt = GetStringFromUrl("https://www.sysnet.pe.kr");

                led7.Write(txt != null && txt.Length != 0);
                Thread.Sleep(1000);
            }
        }

        private static void EnableNetwork()
        {
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface ni
                = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];

            ni.PhysicalAddress = new byte[] { 0x00, 0x15, 0x5D, 0x51, 0x01, 0x06 };
            ni.EnableDynamicDns();
            ni.EnableDhcp();
            ni.RenewDhcpLease();
        }

        private static string GetStringFromUrl(string url)
        {
            HttpWebRequest hwr = HttpWebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse response = null;

            try
            {
                response = hwr.GetResponse() as HttpWebResponse;

                Stream respStream = response.GetResponseStream();
                respStream.Read(_contentBuffer, 0, _contentBuffer.Length);

                response.Close();
                hwr.Dispose();

                return new string(Encoding.UTF8.GetChars(_contentBuffer));
            }
            catch { }

            return null;
        }
    }
}

위의 소스 코드를 조금만 변형하면, 웹을 이용한 장치 제어를 매우 쉽게 구현할 수 있습니다. 게다가 라인 단위의 실시간 디버깅 기능도 제공하니 이만큼 편한 개발 환경이 없을 것입니다.

반면, 당연히 단점이 있습니다. 기본적으로 TinyCLR이 올라가기 때문에 점유되는 메모리가 있으니 다른 환경에 비해 메모리 관리를 잘 해야 합니다. 사실 제가 가지고 있던 구형 넷두이노 플러스는 가용한 RAM 용량이 50+ KB라고 하니 애당초 복잡한 응용 프로그램으로는 사용할 수 없다고 봐야 합니다. 그나마 신형 모델(넷두이노 3)은 3배나 넓어졌다고 하지만... ^^; 그래도 164+ KB라고 하니 데스크톱 환경에서처럼 메모리를 신경 쓰지 않고 사용할 수는 없습니다.

그렇긴 하지만, 대개의 경우 IoT 제품들이 구현하는 기능들이 단순하다는 것을 감안하면 메모리가 문제 되는 경우는 많지 않으므로... 뭐랄까, 만약 C# 개발자라면 ^^ 하나쯤 가지고 노는 것도 재미있을만한... 그런 제품입니다. 쓰다 보니 제품 홍보가 되었는데, 실은 다른 보드들의 코딩을 실습하면서 넷두이노가 얼마나 개발 환경이 편했는지 새삼 느끼게 되었다는!!! ^^;




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 10/4/2018]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2021-08-21 12시10분
Enterprise-Grade IoT Full .NET, Real Embedded Secure & Scalable
 - Meadow is a complete, IoT platform with defense-grade security that runs full .NET Standard applications on embeddable microcontrollers.
; https://www.wildernesslabs.co/

Hello, Meadow!
; http://developer.wildernesslabs.co/Meadow/Getting_Started/Hello_World/
정성태

... [106]  107  108  109  110  111  112  113  114  115  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11271정성태8/19/201719142VS.NET IDE: 119. Visual Studio 2017에서 .NET Core 2.0 프로젝트 환경 구성하는 방법
11270정성태8/17/201730578.NET Framework: 673. C#에서 enum을 boxing 없이 int로 변환하기 [2]
11269정성태8/17/201721368디버깅 기술: 93. windbg - 풀 덤프에서 .NET 스레드의 상태를 알아내는 방법
11268정성태8/14/201720964디버깅 기술: 92. windbg - C# Monitor Lock을 획득하고 있는 스레드 찾는 방법
11267정성태8/10/201725049.NET Framework: 672. 모노 개발 환경
11266정성태8/10/201724823.NET Framework: 671. C# 6.0 이상의 소스 코드를 Visual Studio 설치 없이 명령행에서 컴파일하는 방법
11265정성태8/10/201753098기타: 66. 도서: 시작하세요! C# 7.1 프로그래밍: 기본 문법부터 실전 예제까지 [11]
11264정성태8/9/201723960오류 유형: 414. UWP app을 signtool.exe로 서명 시 0x8007000b 오류 발생
11263정성태8/9/201719432오류 유형: 413. The C# project "..." is targeting ".NETFramework, Version=v4.0", which is not installed on this machine. [3]
11262정성태8/5/201718180오류 유형: 412. windbg - SOS does not support the current target architecture. [3]
11261정성태8/4/201720746디버깅 기술: 91. windbg - 풀 덤프 파일로부터 강력한 이름의 어셈블리 추출 후 사용하는 방법
11260정성태8/3/201718840.NET Framework: 670. C# - 실행 파일로부터 공개키를 추출하는 방법
11259정성태8/2/201718118.NET Framework: 669. 지연 서명된 어셈블리를 sn.exe -Vr 등록 없이 사용하는 방법
11258정성태8/1/201718872.NET Framework: 668. 지연 서명된 DLL과 서명된 DLL의 차이점파일 다운로드1
11257정성태7/31/201719109.NET Framework: 667. bypassTrustedAppStrongNames 옵션 설명파일 다운로드1
11256정성태7/25/201720544디버깅 기술: 90. windbg의 lm 명령으로 보이지 않는 .NET 4.0 ClassLibrary를 명시적으로 로드하는 방법 [1]
11255정성태7/18/201723140디버깅 기술: 89. Win32 Debug CRT Heap Internals의 0xBAADF00D 표시 재현 [1]파일 다운로드3
11254정성태7/17/201719447개발 환경 구성: 322. "Visual Studio Emulator for Android" 에뮬레이터를 "Android Studio"와 함께 쓰는 방법
11253정성태7/17/201719701Math: 21. "Coding the Matrix" 문제 2.5.1 풀이 [1]파일 다운로드1
11252정성태7/13/201718407오류 유형: 411. RTVS 또는 PTVS 실행 시 Could not load type 'Microsoft.VisualStudio.InteractiveWindow.Shell.IVsInteractiveWindowFactory2'
11251정성태7/13/201717031디버깅 기술: 88. windbg 분석 - webengine4.dll의 MgdExplicitFlush에서 발생한 System.AccessViolationException의 crash 문제 (2)
11250정성태7/13/201720650디버깅 기술: 87. windbg 분석 - webengine4.dll의 MgdExplicitFlush에서 발생한 System.AccessViolationException의 crash 문제 [1]
11249정성태7/12/201718425오류 유형: 410. LoadLibrary("[...].dll") failed - The specified procedure could not be found.
11248정성태7/12/201724869오류 유형: 409. pip install pefile - 'cp949' codec can't decode byte 0xe2 in position 208687: illegal multibyte sequence
11247정성태7/12/201719187오류 유형: 408. SqlConnection 객체 생성 시 무한 대기 문제파일 다운로드1
11246정성태7/11/201718044VS.NET IDE: 118. Visual Studio - 다중 폴더에 포함된 파일들에 대한 "Copy to Output Directory"를 한 번에 설정하는 방법
... [106]  107  108  109  110  111  112  113  114  115  116  117  118  119  120  ...