源码下载:

nbiot_module程序(java netbean) -> 提取码

UdpServer程序(C# vs2010) -> 提取码

QQ:505645074

前提条件:开NB卡的时候需要绑定私有ip(电信运营商设置),链路有效连接为30秒,超时了服务器不能给NB模块主发送数据。如果需要服务器主动给NB模块发送指令,需要走电信平台。

《UDP网络通信协议规范》

通信采用GB2312编码格式

数据包格式:

标示符=长度#设备编号#任务id#包类型#包内容#

备注

长度: 4位不足补0,从标示符#到#之间的长度大小

1. 包内容为空

HTEMP=0026#1533022506#Meter-001#01##

2. 包内容含有多个字段

HTEMP=0043#1533022506#Meter-001#01#get-version@nb001#

3. 包内容含有多个字段(字段间用@分割,字段内的数组用[{},{}])

HTEMP=0261#WaterMeter-001#1520557005#03#buildid=44@edmid=37@meter=1228@denddate=2018-02-05 17:36:22@[{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}]#

一.心跳包 
HTEMP=0026#Meter-001#1533022506#01##
HTEMP=0028#Meter-001#1533022506#01#ok#

二.时间同步     
HTEMP=0026#Meter-001#1533022506#02##
HTEMP=0045#Meter-001#1533022506#02#2018-08-16 09:50:58#

三.数据上传 
HTEMP=0256#Meter-001#1520557005#03#buildid=44@edmid=37@meter=1228@denddate=2018-02-05 17:36:22@[{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}]#
HTEMP=0048#Meter-001#1520557005#03#error@服务器返回失败!#
HTEMP=0028#Meter-001#1520557005#03#ok#

四.版本查询     
HTEMP=0044#Meter-0001#1533022507#04#get-version@nb001#
HTEMP=0028#Meter-0001#1533022507#04#2#

五.软件更新 
HTEMP=0042#Meter-0001#1533022508#05#get-count@nb001#
HTEMP=0029#Meter-0001#1533022508#05#16#

六.软件下载 
HTEMP=0044#Meter-0001#1533022508#06#do-update@nb001@1#
HTEMP=0495#Meter-0001#1533022508#06#504B03041400000008007A640F4D6BEBFDBA000E00004D2E000007000000636F6D732E7079D51A6B73D356F6BB7FC55D7932926AC7D80EA1901DB10D8901CF244ED636FB189AF1C8D275A246B6BC924C603B9D816E29852DD09D6E976D0B944E4BB7B3DB02EDD22729FD3328099FF80B7BEE4B962C3BA4E36DBBAB99C4D23DCF7BCEB9F79C7BA4349A7C6612198E6975566750CF6F350E929194D5EE3AAE8FBC339EB8B59DD55540128FBED5C6E2BEED98CD9ED7F0D713033913B7AC0EF690EE21C3F393707647C0EC6E1446C3F57B7D2CF23412D337BA114C780A27835D4BB7C553CFB56DAB59CCB2DF#

七.版本更新 
HTEMP=0046#Meter-0001#1533022509#07#update-version@56@2#
HTEMP=0029#Meter-0001#1533022509#07#ok#

package com.module.ui;

import com.module.serial.BC95SerialPort;

import com.module.serial.CCommondFunc;

import com.module.serial.CTxtHelper;

public class Program {

static int port = 9096;

static BC95SerialPort serialport = new BC95SerialPort();

public static void main(String[] args) {

String com = "COM3";// /dev/ttyAMA0

boolean ret = serialport.init(com, "117.25.162.156", "8292");

if (ret)

{

System.out.println("串口打开成功:" + com);

//ret = serialport.ReStartModule();

if (ret)

{

Heart();

Time();

Upload();

Update();

}

}

else {

System.out.println("串口打开失败:" + com);

}

}

static void Heart() {

String protocol = "HTEMP=0026#Meter-001#1533022506#01##";

String outPut = serialport.PassData1(protocol);

CTxtHelper.AppendLog("===========================");

CTxtHelper.AppendLog("[input]:" + protocol);

CTxtHelper.AppendLog("[output]:" + outPut);

CTxtHelper.AppendLog("===========================");

}

static void Time() {

String protocol = "HTEMP=0213#Meter-8888#1533022507#03#buildid=44@edmid=37@meter=1604@senddate=2018-07-31 15:35:02@[{32,233.1}+{33,217.5}+{34,229.1}+{35,0.0}+{36,0.0}+{37,0.0}+{40,0.0}+{41,0.0}+{38,0.0}+{39,50.01}+{56,0.0}+{54,0.0}+{55,0.0}]#";

String outPut = serialport.PassData1(protocol);

CTxtHelper.AppendLog("===========================");

CTxtHelper.AppendLog("[input]:" + protocol);

CTxtHelper.AppendLog("[output]:" + outPut);

CTxtHelper.AppendLog("===========================");

}

static void Upload() {

String protocol = "HTEMP=0213#Meter-8888#1533022507#03#buildid=44@edmid=37@meter=1604@senddate=2018-07-31 15:35:02@[{32,233.1}+{33,217.5}+{34,229.1}+{35,0.0}+{36,0.0}+{37,0.0}+{40,0.0}+{41,0.0}+{38,0.0}+{39,50.01}+{56,0.0}+{54,0.0}+{55,0.0}]#";

String outPut = serialport.PassData1(protocol);

CTxtHelper.AppendLog("===========================");

CTxtHelper.AppendLog("[input]:" + protocol);

CTxtHelper.AppendLog("[output]:" + outPut);

CTxtHelper.AppendLog("===========================");

}

static void Update() {

String back = ""; String data = "";

String protocol = "HTEMP=0044#Meter-0001#1533022507#04#get-version@nb001#";

String outPut = serialport.PassData1(protocol);

CTxtHelper.AppendLog("===========================");

CTxtHelper.AppendLog("[input]:" + protocol);

CTxtHelper.AppendLog("[output]:" + outPut);

CTxtHelper.AppendLog("===========================");

protocol = "HTEMP=0042#Meter-0001#1533022508#05#get-count@nb001#";

back = serialport.PassData1(protocol);

CTxtHelper.AppendLog("===========================");

CTxtHelper.AppendLog("[input]:" + protocol);

CTxtHelper.AppendLog("[output]:" + back);

CTxtHelper.AppendLog("===========================");

if (!"".endsWith(back))

{

data = back.split("#")[4];

int count = Integer.parseInt(data);

String[] buffer = new String[count];

String[] source = new String[count];

CTxtHelper.AppendLog("Count:" + String.valueOf(count));

for (int i = 0; i < count; i++)

{

buffer[i] = "HTEMP=[XX]#Meter-0001#1533022508#06#do-update@nb001@" + String.valueOf(i + 1) + "#";

}

int tryIndex = 0; boolean downresult = true;

while (tryIndex++ < 10)

{

downresult = true;

for (int i = 0; i < count; i++)

{

protocol = buffer[i];

if (!"".endsWith(protocol))

{

downresult = false;

back = serialport.PassData1(protocol);

if (!"".endsWith(back))

{

buffer[i] = "";

data = back.split("#")[4];

source[i] = data;

}

else

{

CTxtHelper.AppendLog("Fail:" + String.valueOf(i + 1));

}

}

}

if (downresult) break;

}

if (downresult)

{

StringBuilder strFileData = new StringBuilder();

for (int i = 0; i < count; i++)

{

strFileData.append(source[i]);

}

byte[] arrFileData = CCommondFunc.hexStringToBytes(strFileData.toString());

CCommondFunc.writeToFile(arrFileData, "D:\\NBDown\\config.zip");

}

}

}

}

run:
串口打开成功:COM3
20190222 14:21:54 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:21:55 send data=AT+NSOST=0,117.25.162.156,8292,36,4854454D503D30303236234D657465722D30303123313533333032323530362330312323

20190222 14:21:57 send data=AT+NSORF=0,38

20190222 14:21:58 recv:HTEMP=0028#Meter-001#1533022506#01#ok#
20190222 14:21:58 send data=AT+NSOCL=0

20190222 14:21:58 ===========================
20190222 14:21:58 [input]:HTEMP=0026#Meter-001#1533022506#01##
20190222 14:21:58 [output]:HTEMP=0028#Meter-001#1533022506#01#ok#
20190222 14:21:58 ===========================
20190222 14:21:58 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:21:59 send data=AT+NSOST=0,117.25.162.156,8292,223,4854454D503D30323133234D657465722D383838382331353333303232353037233033236275696C6469643D34344065646D69643D3337406D657465723D313630344073656E64646174653D323031382D30372D33312031353A33353A3032405B7B33322C3233332E317D2B7B33332C3231372E357D2B7B33342C3232392E317D2B7B33352C302E307D2B7B33362C302E307D2B7B33372C302E307D2B7B34302C302E307D2B7B34312C302E307D2B7B33382C302E307D2B7B33392C35302E30317D2B7B35362C302E307D2B7B35342C302E307D2B7B35352C302E307D5D23

20190222 14:22:01 send data=AT+NSORF=0,39

20190222 14:22:02 recv:HTEMP=0029#Meter-8888#1533022507#03#ok#
20190222 14:22:02 send data=AT+NSOCL=0

20190222 14:22:02 ===========================
20190222 14:22:02 [input]:HTEMP=0213#Meter-8888#1533022507#03#buildid=44@edmid=37@meter=1604@senddate=2018-07-31 15:35:02@[{32,233.1}+{33,217.5}+{34,229.1}+{35,0.0}+{36,0.0}+{37,0.0}+{40,0.0}+{41,0.0}+{38,0.0}+{39,50.01}+{56,0.0}+{54,0.0}+{55,0.0}]#
20190222 14:22:02 [output]:HTEMP=0029#Meter-8888#1533022507#03#ok#
20190222 14:22:02 ===========================
20190222 14:22:02 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:03 send data=AT+NSOST=0,117.25.162.156,8292,223,4854454D503D30323133234D657465722D383838382331353333303232353037233033236275696C6469643D34344065646D69643D3337406D657465723D313630344073656E64646174653D323031382D30372D33312031353A33353A3032405B7B33322C3233332E317D2B7B33332C3231372E357D2B7B33342C3232392E317D2B7B33352C302E307D2B7B33362C302E307D2B7B33372C302E307D2B7B34302C302E307D2B7B34312C302E307D2B7B33382C302E307D2B7B33392C35302E30317D2B7B35362C302E307D2B7B35342C302E307D2B7B35352C302E307D5D23

20190222 14:22:05 send data=AT+NSORF=0,39

20190222 14:22:06 recv:HTEMP=0029#Meter-8888#1533022507#03#ok#
20190222 14:22:06 send data=AT+NSOCL=0

20190222 14:22:06 ===========================
20190222 14:22:06 [input]:HTEMP=0213#Meter-8888#1533022507#03#buildid=44@edmid=37@meter=1604@senddate=2018-07-31 15:35:02@[{32,233.1}+{33,217.5}+{34,229.1}+{35,0.0}+{36,0.0}+{37,0.0}+{40,0.0}+{41,0.0}+{38,0.0}+{39,50.01}+{56,0.0}+{54,0.0}+{55,0.0}]#
20190222 14:22:06 [output]:HTEMP=0029#Meter-8888#1533022507#03#ok#
20190222 14:22:06 ===========================
20190222 14:22:06 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:07 send data=AT+NSOST=0,117.25.162.156,8292,54,4854454D503D30303434234D657465722D303030312331353333303232353037233034236765742D76657273696F6E406E6230303123

20190222 14:22:08 send data=AT+NSORF=0,38

20190222 14:22:09 recv:HTEMP=0028#Meter-0001#1533022507#04#3#
20190222 14:22:09 send data=AT+NSOCL=0

20190222 14:22:09 ===========================
20190222 14:22:09 [input]:HTEMP=0044#Meter-0001#1533022507#04#get-version@nb001#
20190222 14:22:09 [output]:HTEMP=0028#Meter-0001#1533022507#04#3#
20190222 14:22:09 ===========================
20190222 14:22:09 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:10 send data=AT+NSOST=0,117.25.162.156,8292,52,4854454D503D30303432234D657465722D303030312331353333303232353038233035236765742D636F756E74406E6230303123

20190222 14:22:11 send data=AT+NSORF=0,38

20190222 14:22:12 recv:HTEMP=0028#Meter-0001#1533022508#05#5#
20190222 14:22:12 send data=AT+NSOCL=0

20190222 14:22:12 ===========================
20190222 14:22:12 [input]:HTEMP=0042#Meter-0001#1533022508#05#get-count@nb001#
20190222 14:22:12 [output]:HTEMP=0028#Meter-0001#1533022508#05#5#
20190222 14:22:12 ===========================
20190222 14:22:12 Count:5
20190222 14:22:12 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:13 send data=AT+NSOST=0,117.25.162.156,8292,54,4854454D503D30303434234D657465722D30303031233135333330323235303823303623646F2D757064617465406E62303031403123

20190222 14:22:15 send data=AT+NSORF=0,505

20190222 14:22:16 recv:HTEMP=0495#Meter-0001#1533022508#06#504B03041400000008007A880E4D604C094741030000F83F00000A000000436F6E6669672E696E69EDDABF4B1C411407F05EF07F58B0CCBACC9B796F7E2C1C5C93229080C4F2B8C264AF388C0AE7A592D4214148FA5456E9D3247085FF4C8C76F917B2A76E4EE520F13B06C34B1461389D553FF7DC37EFEB7D9F1D535C3761DD5141BE165393148FC7FBD3D16E3178B45153B215F9D87E54AEDCD89B4CEB488986AB2BF3F71B3BC5154FEB6240142A4F95E58A92A9AD786386C5F39DA6E78A666BBAD57B329A8E26EBB17D5B2371CE58EB85D78C5B7BF672FCA219373DE6FEA8D969172EF477E65FDC23#
20190222 14:22:16 send data=AT+NSOCL=0

20190222 14:22:17 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:17 send data=AT+NSOST=0,117.25.162.156,8292,54,4854454D503D30303434234D657465722D30303031233135333330323235303823303623646F2D757064617465406E62303031403223

20190222 14:22:19 send data=AT+NSORF=0,505

20190222 14:22:21 recv:HTEMP=0495#Meter-0001#1533022508#06#6FB8BF3FDA6DDA0B8C7AD62CBEB1D44E6A63FB8303674BEB5C45AF1E1C3857DAF68790F9924B6BD3C5A3529ACACC17BE5B84CB059B6E41DDA762B748A5B4ABF905A4DB27DC2D2E2E395C8621C5E66F60EC6D2FDB9B6048510649B5312864BB17AF48AF0F923320230C19F441461C9208868CEA20C966400A0C99F4414A0624DC6CBCD1079970480B371B4FEA206D46B3B10186B4FA20339A8DB330A45307E95C06A48721591FA4C721D9C090FA261BCE986C9861C82B938D16C88CE30FE3C71F7D930D671C7FF0F4C7EB9B6C24A3D9087EFCD137D94840216D6DE0593B689B6CCE317048B8D904D20729#
20190222 14:22:21 send data=AT+NSOCL=0

20190222 14:22:21 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:22 send data=AT+NSOST=0,117.25.162.156,8292,54,4854454D503D30303434234D657465722D30303031233135333330323235303823303623646F2D757064617465406E62303031403323

20190222 14:22:24 send data=AT+NSORF=0,505

20190222 14:22:25 recv:HTEMP=0495#Meter-0001#1533022508#06#1990708C16AC3EC88843123CD904A70E128FD1DABDF06413581FA4CF80BCF6A71D2BF67510474B14E730978A9E0C7C88F4E78AD4299A2A768AB2508CF7A1188BC1C3C9646F322C4E3F7C39797FF875363B797B346E4E3E7F3A9DBDFBF6E6E3D9D1E1D9F1EBF2E5B8B942524EB7F6B7DB471632CBAFBDF92BE5A54F8F8507CF20EAEADC1ABCCEAF43FECB756ECD9FAB736BD03ABFC551ED469D7B7D75CE1975CE489D734E9DB3B9A268168A5C854E31DC87A2A0B518FE13FE94B8835B052FBF55843B797A6E75AB08FA6E1519C388C37386A80ED2650C230EFE9F7E48FA203372060787DA515FF2E5120E#
20190222 14:22:25 send data=AT+NSOCL=0

20190222 14:22:26 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:26 send data=AT+NSOST=0,117.25.162.156,8292,54,4854454D503D30303434234D657465722D30303031233135333330323235303823303623646F2D757064617465406E62303031403423

20190222 14:22:28 send data=AT+NSORF=0,505

20190222 14:22:30 recv:HTEMP=0495#Meter-0001#1533022508#06#C970A81DF5255FEC3220E16613F5255F9C116A0BDC6CA2BEE44B32426D8127A5A82FF9928C662370A81DF5452B029F235DFBFBC090C0ECFE57439E63E09070A81D833E488F43129C9AC6A80E924C0624DE6C923E48CE8084CF91C9E883CC6836163E47265207692903120E2D92D5072919907068919C3EC884433A38B448AC0E127FD977BB176F36A20F32E090F8CBBE93BEC986339A0DFEB2EFA46FB2E18C66C3706891144C36AB2B3F00504B01021F001400000008007A880E4D604C094741030000F83F00000A0024000000000000002000000000000000436F6E6669672E696E690A002000000000#
20190222 14:22:30 send data=AT+NSOCL=0

20190222 14:22:30 send data=AT+NSOCR=DGRAM,17,9358,1

20190222 14:22:31 send data=AT+NSOST=0,117.25.162.156,8292,54,4854454D503D30303434234D657465722D30303031233135333330323235303823303623646F2D757064617465406E62303031403523

20190222 14:22:32 send data=AT+NSORF=0,139

20190222 14:22:33 recv:HTEMP=0129#Meter-0001#1533022508#06#00010018006AF5BFB8AD33D401A3CC6F80AB28D401A9253DCC7833D401504B050600000000010001005C000000690300000000#
20190222 14:22:33 send data=AT+NSOCL=0

BUILD SUCCESSFUL (total time: 40 seconds)

完成升级包下载

NBIOT实现UDP协议的发送和接收(包含软件升级)的更多相关文章

  1. C#中UDP数据的发送、接收

    Visual C# UDP数据的发送、接收包使用的主要类及其用法: 用Visual C# UDP协议的实现,最为常用,也是最为关键的类就是UdpClient,UdpClient位于命名空间System ...

  2. Udp广播的发送和接收(iOS + AsyncUdpSocket)下篇

    接上篇C#的Udp广播的发送和接收 http://www.cnblogs.com/JimmyBright/p/4637090.html ios中使用AsyncUdpSocket处理Udp的消息非常方便 ...

  3. udp网络程序-发送、接收数据

    1. udp网络程序-发送数据 创建一个基于udp的网络程序流程很简单,具体步骤如下: 创建客户端套接字 发送/接收数据 关闭套接字 代码如下: #coding=utf-8from socket im ...

  4. 【Java】学习路径54-使用UDP协议开发发送、接收端

    UDP协议,简单的说就是,发信息. 不管对方有没有收到. 发送端: import java.net.*; public class UDP_Send { public static void main ...

  5. SMTP协议及POP3协议-邮件发送和接收原理(转)

    本文转自https://blog.csdn.net/qq_15646957/article/details/52544099 感谢作者 一. 邮件开发涉及到的一些基本概念 1.1.邮件服务器和电子邮箱 ...

  6. Udp广播的发送与接收(C#+UdpClient) 上篇

    简介: Udp广播消息用在局域网的消息传递很方便.本文使用UdpClient类在WPF下实现Udp广播收发 发送: void MainWindow_Loaded(object sender, Rout ...

  7. Java中udp/tcp的发送和接收

    InetAddress UDP例程: 发送数据: 接收数据: 结果: TCP例程: 发送数据: 接收数据: 结果:

  8. Java网络编程(UDP协议:发送端)

    package WebProgramingDemo; import java.io.IOException; import java.net.DatagramPacket; import java.n ...

  9. java下udp的DatagramSocket 发送与接收

    发送 package cn.stat.p4.ipdemo; import java.io.BufferedReader; import java.io.IOException; import java ...

随机推荐

  1. dijit/_WidgetBase

    英文地址:http://dojotoolkit.org/reference-guide/1.10/dijit/_WidgetBase.html 介绍 dijit/_WidgetBase是Dijit包中 ...

  2. PyQt5-TableWidget 表格视图

    基于PyQt5 postgreSQL实现简单的数据插入.数据表格查询. 运行前需要安装psycopg2 模块,配置好postgerSQL. 先看效果图: 第1列为日期时间.第2列为自增1的编号.第3到 ...

  3. 5.Python网络编程_通过继承实现多线程

    import threading import time #继承形式的多线程,适合于程序比较复杂的情况 class MyThread(threading.Thread): #t.start()会调用r ...

  4. 201871010113-刘兴瑞《面向对象程序设计(java)》第四周学习总结

    项目 内容 这个作业属于哪个课程 <任课教师博客主页链接>https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 <作业链接地址>http ...

  5. C++ 模板特化、偏特化测试程序

    #include <iostream> // 偏特化的模板不会自己添加构造函数 ctor 和 析构函数 dtor #if 1 // P1 template <typename T1, ...

  6. SDOI 2009 学校食堂

    洛谷 P2157 [SDOI2009]学校食堂 洛谷传送门 JDOJ 1924: [SDOI2009]学校食堂Dining JDOJ传送门 Description 小F 的学校在城市的一个偏僻角落,所 ...

  7. win10 + 3ds Max 2014 问题记录

    3ds Max 下载: https://zixue.3d66.com/popsoft_201.html VRay 下载: https://zixue.3d66.com/softhtml/showsof ...

  8. Flutter命令突然无响应、vscode突然无法连接到IOS模拟器

    这周过来突然flutter相关命令运行都没有响应, 打开任务管理器,关闭所有dart进程即可解决

  9. 记一次Lua语言中死循环查错

    前言 如果在Lua语言中某一处死循环了!你特么的怎么去查出这特么的该死的循环到底在特么的哪里!!! 重现步骤 一打开技能界面,整个游戏就卡死不动了 开始排查 查看一下cpu占用率,unity占用60% ...

  10. JQuery插件 aos.js-添加动画效果

    原文地址:http://www.mamicode.com/info-detail-1785357.html 简介: aos.js是一款效果超赞的页面滚动元素动画jQuery动画库插件.该动画库可以在页 ...