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

... [91]  92  93  94  95  96  97  98  99  100  101  102  103  104  105  ...
NoWriterDateCnt.TitleFile(s)
11367정성태11/25/201720496개발 환경 구성: 337. 윈도우 운영체제의 route 명령어 사용법
11366정성태11/25/201712299오류 유형: 430. 이벤트 로그 - Cryptographic Services failed while processing the OnIdentity() call in the System Writer Object.
11365정성태11/25/201714574오류 유형: 429. 이벤트 로그 - User Policy could not be updated successfully
11364정성태11/24/201715692사물인터넷: 11. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스로 쓰는 방법 (절대 좌표) [2]
11363정성태11/23/201715386사물인터넷: 10. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스 + 키보드로 쓰는 방법 (두 번째 이야기)
11362정성태11/22/201713056오류 유형: 428. 윈도우 업데이트 KB4048953 - 0x800705b4 [2]
11361정성태11/22/201715612오류 유형: 427. 이벤트 로그 - Filter Manager failed to attach to volume '\Device\HarddiskVolume??' 0xC03A001C
11360정성태11/22/201715405오류 유형: 426. 이벤트 로그 - The kernel power manager has initiated a shutdown transition.
11359정성태11/16/201714763오류 유형: 425. 윈도우 10 Version 1709 (OS Build 16299.64) 업그레이드 시 발생한 문제 2가지
11358정성태11/15/201719045사물인터넷: 9. Visual Studio 2017에서 Raspberry Pi C++ 응용 프로그램 제작 [1]
11357정성태11/15/201719849개발 환경 구성: 336. 윈도우 10 Bash 쉘에서 C++ 컴파일하는 방법
11356정성태11/15/201721209사물인터넷: 8. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스 + 키보드로 쓰는 방법 [4]
11355정성태11/15/201717700사물인터넷: 7. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스로 쓰는 방법 [2]파일 다운로드2
11354정성태11/14/201720982사물인터넷: 6. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 키보드로 쓰는 방법 [8]
11353정성태11/14/201718742사물인터넷: 5. Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 이더넷 카드로 쓰는 방법 [1]
11352정성태11/14/201714358사물인터넷: 4. Samba를 이용해 윈도우와 Raspberry Pi간의 파일 교환 [1]
11351정성태11/7/201717339.NET Framework: 698. C# 컴파일러 대신 직접 구현하는 비동기(async/await) 코드 [6]파일 다운로드1
11350정성태11/1/201713651디버깅 기술: 108. windbg 분석 사례 - Redis 서버로의 호출을 기다리면서 hang 현상 발생
11349정성태10/31/201713542디버깅 기술: 107. windbg - x64 SOS 확장의 !clrstack 명령어가 출력하는 Child SP 값의 의미 [1]파일 다운로드1
11348정성태10/31/201710951디버깅 기술: 106. windbg - x64 역어셈블 코드에서 닷넷 메서드 호출의 인자를 확인하는 방법
11347정성태10/28/201714456오류 유형: 424. Visual Studio - "클래스 다이어그램 보기" 시 "작업을 완료할 수 없습니다. 해당 인터페이스를 지원하지 않습니다." 오류 발생
11346정성태10/25/201710795오류 유형: 423. Windows Server 2003 - The client-side extension could not remove user policy settings for 'Default Domain Policy {...}' (0x8007000d)
11338정성태10/25/201710878.NET Framework: 697. windbg - SOS DumpMT의 "BaseSize", "ComponentSize" 값에 대한 의미파일 다운로드1
11337정성태10/24/201711841.NET Framework: 696. windbg - SOS DumpClass/DumpMT의 "Vtable Slots", "Total Method Slots", "Slots in VTable" 값에 대한 의미파일 다운로드1
11336정성태10/20/201712300.NET Framework: 695. windbg - .NET string의 x86/x64 메모리 할당 구조
11335정성태10/18/201711862.NET Framework: 694. 닷넷 - <Module> 클래스의 용도
... [91]  92  93  94  95  96  97  98  99  100  101  102  103  104  105  ...