Microsoft MVP성태의 닷넷 이야기
사물인터넷: 48. 넷두이노의 C# 네트워크 프로그램 [링크 복사], [링크+제목 복사],
조회: 22677
글쓴 사람
정성태 (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/
정성태

... 76  77  78  79  80  81  82  83  84  85  [86]  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11817정성태2/17/201917367오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201921259Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201919423오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201918081오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201919104.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/201916447오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201922294오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
11810정성태2/11/201919312.NET Framework: 808. .NET Profiler - GAC 모듈에서 GAC 비-등록 모듈을 참조하는 경우의 문제
11809정성태2/11/201922107.NET Framework: 807. ClrMD를 이용해 메모리 덤프 파일로부터 특정 인스턴스를 참조하고 있는 소유자 확인
11808정성태2/8/201923523디버깅 기술: 123. windbg - 닷넷 응용 프로그램의 메모리 누수 분석
11807정성태1/29/201921317Windows: 156. 가상 디스크의 용량을 복구 파티션으로 인해 늘리지 못하는 경우 [4]
11806정성태1/29/201920395디버깅 기술: 122. windbg - 덤프 파일로부터 PID와 환경 변수 등의 정보를 구하는 방법
11805정성태1/28/201923166.NET Framework: 806. C# - int []와 object []의 차이로 이해하는 제네릭의 필요성 [4]파일 다운로드1
11804정성태1/24/201920739Windows: 155. diskpart - remove letter 이후 재부팅 시 다시 드라이브 문자가 할당되는 경우
11803정성태1/10/201919736디버깅 기술: 121. windbg - 닷넷 Finalizer 스레드가 멈춰있는 현상
11802정성태1/7/201921342.NET Framework: 805. 두 개의 윈도우를 각각 실행하는 방법(Windows Forms, WPF)파일 다운로드1
11801정성태1/1/201922367개발 환경 구성: 427. Netsh의 네트워크 모니터링 기능 [3]
11800정성태12/28/201821669오류 유형: 509. WCF 호출 오류 메시지 - System.ServiceModel.CommunicationException: Internal Server Error
11799정성태12/19/201823672.NET Framework: 804. WPF(또는 WinForm)에서 UWP UI 구성 요소 사용하는 방법 [3]파일 다운로드1
11798정성태12/19/201822269개발 환경 구성: 426. vcpkg - "Building vcpkg.exe failed. Please ensure you have installed Visual Studio with the Desktop C++ workload and the Windows SDK for Desktop C++"
11797정성태12/19/201817992개발 환경 구성: 425. vcpkg - CMake Error: Problem with archive_write_header(): Can't create '' 빌드 오류
11796정성태12/19/201818831개발 환경 구성: 424. vcpkg - "File does not have expected hash" 오류를 무시하는 방법
11795정성태12/19/201822295Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]
11794정성태12/16/201818166오류 유형: 508. Get-AzureWebsite : Request to a downlevel service failed.
11793정성태12/16/201821044개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법 [1]
11792정성태12/11/201819874Graphics: 34. .NET으로 구현하는 OpenGL (11) - Per-Pixel Lighting파일 다운로드1
... 76  77  78  79  80  81  82  83  84  85  [86]  87  88  89  90  ...