Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve lwm2m User experience #16

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
<description>IoT Protocol Client CLI</description>
<longDescription>
Toolkit is a client command line tool that supports multiple IoT protocols.
CoAP and MQTT protocols are currently supported. more protocols will be supported in the future.
CoAP、MQTT and LwM2M protocols are currently supported. more protocols will be supported in the future.
it is written in the java language, but does not rely on the JRE environment.
</longDescription>
<website>https://github.com/IoT-Technology/IoT-Toolkit</website>
Expand All @@ -271,6 +271,8 @@
<tag>mqtt-client</tag>
<tag>coap</tag>
<tag>coap-client</tag>
<tag>lwm2m</tag>
<tag>lwm2m-client</tag>
</tags>
<docsUrl>https://github.com/IoT-Technology/IoT-Toolkit/wiki</docsUrl>
</project>
Expand Down
4 changes: 2 additions & 2 deletions toolkit-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<executable-suffix />
<directory>${project.basedir}/target</directory>
<skipCompress>false</skipCompress>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<graalvm-buildtools.version>0.9.27</graalvm-buildtools.version>
<picocli-codegen.version>4.6.3</picocli-codegen.version>
Expand Down
2 changes: 1 addition & 1 deletion toolkit-app/src/main/resources/i18n/messages_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ nb.cmd.endTime.desc=\u67e5\u8be2\u8bbe\u5907\u65e5\u5fd7\u6570\u636e\u5217\u8868
nbType.prompt=\u8bf7\u9009\u62e9 Nb-IoT \u5e73\u53f0
nb.new.config.desc=\u589e\u52a0\u4e00\u4e2a\u65b0\u7684\u914d\u7f6e
nb.select.config.error=\u8bf7\u8f93\u51650,1,2...\u6216new
nbTelecomAppConfig.prompt=\u8bf7\u9009\u62e9\u60a8\u7684\u79fb\u52a8\u5e94\u7528\u914d\u7f6e:
nbTelecomAppConfig.prompt=\u8bf7\u9009\u62e9\u60a8\u7684\u7535\u4fe1\u5e94\u7528\u914d\u7f6e:
nbTelProjectName.prompt=\u8bf7\u8f93\u5165\u4f60\u7684\u9879\u76ee\u540d\u79f0:
nbTelAppSecret.prompt=\u8bf7\u8f93\u5165\u4f60\u7684\u5e94\u7528\u7684 appSecret:
nbTelAppKey.prompt=\u8bf7\u8f93\u5165\u4f60\u7684\u5e94\u7528\u7684 appKey:
Expand Down
4 changes: 2 additions & 2 deletions toolkit-coap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<packaging>jar</packaging>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions toolkit-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<packaging>jar</packaging>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions toolkit-mqtt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<name>IoT Technology ToolKit MQTT</name>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions toolkit-nbiot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<name>IoT Technology Toolkit NB-IoT</name>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import iot.technology.client.toolkit.common.rule.TkNode;
import iot.technology.client.toolkit.common.rule.TkProcessor;
import iot.technology.client.toolkit.common.utils.ObjectUtils;
import iot.technology.client.toolkit.common.utils.StringUtils;
import iot.technology.client.toolkit.nb.service.NbBizService;
import iot.technology.client.toolkit.nb.service.NbConfigSettingsDomain;
import iot.technology.client.toolkit.nb.service.NbRuleChainProcessor;
import iot.technology.client.toolkit.nb.service.processor.NbSettingsContext;
Expand Down Expand Up @@ -58,7 +56,6 @@
)
public class NbSettingsCommand implements Callable<Integer> {

private final NbBizService bizService = new NbBizService();
private final NbRuleChainProcessor ruleChain = new NbRuleChainProcessor();
private final Map<String, String> processor = ruleChain.getNbRuleChainProcessor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class Lwm2mConfigSetting implements Serializable {

private String lwm2mCertUsage;

private String serial;


public String getLwm2mServer() {
return lwm2mServer;
Expand Down Expand Up @@ -222,4 +224,12 @@ public String getLwm2mCertUsage() {
public void setLwm2mCertUsage(String lwm2mCertUsage) {
this.lwm2mCertUsage = lwm2mCertUsage;
}

public String getSerial() {
return serial;
}

public void setSerial(String serial) {
this.serial = serial;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean check(NodeContext context) {
context.setCheck(true);
return true;
}
System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error")));
System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error")) + "%n");
context.setCheck(false);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import iot.technology.client.toolkit.common.utils.ColorUtils;
import iot.technology.client.toolkit.common.utils.JsonUtils;
import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSetting;
import iot.technology.client.toolkit.nb.service.mobile.domain.settings.MobProjectSettings;

import java.util.List;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean check(NodeContext context) {
context.setCheck(true);
return true;
}
System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error")));
System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error")) + "%n");
context.setCheck(false);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ public void handle(ProcessContext context) {
configStringList.remove(configStringList.get(serial));
FileUtils.updateAllFileContents(SystemConfigConst.SYS_NB_MOBILE_PRODUCT_FILE_NAME, configStringList);
}
if (nbSettingsContext.getNbType().equals(NBTypeEnum.LWM2M.getValue())) {
List<String> configStringList = FileUtils.getDataFromFile(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME);
configStringList.remove(configStringList.get(serial));
FileUtils.updateAllFileContents(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME, configStringList);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import iot.technology.client.toolkit.common.rule.TkProcessor;
import iot.technology.client.toolkit.common.utils.FileUtils;
import iot.technology.client.toolkit.common.utils.JsonUtils;
import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSetting;
import iot.technology.client.toolkit.nb.service.mobile.domain.settings.MobProjectSettings;
import iot.technology.client.toolkit.nb.service.processor.NbSettingsContext;
import iot.technology.client.toolkit.nb.service.telecom.domain.settings.TelProjectSettings;
Expand Down Expand Up @@ -103,5 +104,32 @@ public void handle(ProcessContext context) {
System.out.println(tableInfo);
}
}
if (nbSettingsContext.getNbType().equals(NBTypeEnum.LWM2M.getValue())) {
List<String> configStringList = FileUtils.getDataFromFile(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME);
if (!configStringList.isEmpty()) {
AtomicInteger cal = new AtomicInteger();
List<Lwm2mConfigSetting> lwm2mConfigSettings = new ArrayList<>();
configStringList.stream()
.map(s -> JsonUtils.jsonToObject(s, Lwm2mConfigSetting.class))
.filter(Objects::nonNull)
.forEach(s -> {
s.setSerial(cal + "");
lwm2mConfigSettings.add(s);
cal.getAndIncrement();
});
String tableInfo = AsciiTable.getTable(AsciiTable.BASIC_ASCII_NO_OUTSIDE_BORDER, lwm2mConfigSettings, Arrays.asList(
new Column().header("Serial").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
Lwm2mConfigSetting::getSerial),
new Column().header("Endpoint").minWidth(10).headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT)
.with(Lwm2mConfigSetting::getLwm2mEndpoint),
new Column().header("ServerAndPort").minWidth(10).headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT)
.with(Lwm2mConfigSetting::getServerAndPort),
new Column().header("LifeTime").minWidth(10).headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT)
.with(Lwm2mConfigSetting::getLwm2mLifeTime)
));
System.out.println(tableInfo);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import iot.technology.client.toolkit.common.utils.FileUtils;
import iot.technology.client.toolkit.common.utils.JsonUtils;
import iot.technology.client.toolkit.common.utils.ObjectUtils;
import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSetting;
import iot.technology.client.toolkit.nb.service.mobile.domain.settings.MobProjectSettings;
import iot.technology.client.toolkit.nb.service.processor.NbSettingsContext;
import iot.technology.client.toolkit.nb.service.telecom.domain.settings.TelProjectSettings;
Expand Down Expand Up @@ -74,5 +75,21 @@ public void handle(ProcessContext context) {
System.out.format("ProductId: " + mobProjectSettings.getProductId() + "%n");
System.out.format("AccessKey: " + mobProjectSettings.getAccessKey() + "%n");
}
if (nbSettingsContext.getNbType().equals(NBTypeEnum.LWM2M.getValue())) {
List<String> configStringList = FileUtils.getDataFromFile(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME);
var lwm2mConfigSetting = JsonUtils.jsonToObject(configStringList.get(serial), Lwm2mConfigSetting.class);
System.out.format("Endpoint: " + lwm2mConfigSetting.getLwm2mEndpoint() + "%n");
System.out.format("ServerAndPort: " + lwm2mConfigSetting.getServerAndPort() + "%n");
System.out.format("LifeTime: " + lwm2mConfigSetting.getLwm2mLifeTime() + "%n");
System.out.format("BootstrapServer: " + lwm2mConfigSetting.getLwm2mBootstrapServer() + "%n");
System.out.format("PskIdentity: " + lwm2mConfigSetting.getLwm2mPskIdentity() + "%n");
System.out.format("PskShareKey: " + lwm2mConfigSetting.getLwm2mPskShareKey() + "%n");
System.out.format("ClientPrivateKey: " + lwm2mConfigSetting.getLwm2mClientPrivateKey() + "%n");
System.out.format("ClientPublicKey: " + lwm2mConfigSetting.getLwm2mClientPublicKey() + "%n");
System.out.format("ServerPublicKey: " + lwm2mConfigSetting.getLwm2mServerPublicKey() + "%n");
System.out.format("ClientCert: " + lwm2mConfigSetting.getLwm2mClientCert() + "%n");
System.out.format("ServerCert: " + lwm2mConfigSetting.getLwm2mServerCert() + "%n");
System.out.format("CertUsage: " + lwm2mConfigSetting.getLwm2mCertUsage() + "%n");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void handle(ProcessContext context) {
if (!cmd.hasOption(imeiOption)) {
StringBuilder sb = new StringBuilder();
sb.append(ColorUtils.redError("imei is required")).append(StringUtils.lineSeparator);
sb.append(ColorUtils.blackBold("detail usage please enter: help log"));
sb.append(ColorUtils.blackBold("detail usage please enter: help command"));
System.out.println(sb);
return;
}
Expand All @@ -86,7 +86,7 @@ public void handle(ProcessContext context) {
if (!validateParam(pageNoStr)) {
StringBuilder sb = new StringBuilder();
sb.append(ColorUtils.redError("pageNo is not a number")).append(StringUtils.lineSeparator);
sb.append(ColorUtils.blackBold("detail usage please enter: help list"));
sb.append(ColorUtils.blackBold("detail usage please enter: help command"));
System.out.println(sb);
return;
}
Expand All @@ -99,7 +99,7 @@ public void handle(ProcessContext context) {
if (!validateParam(pageSizeStr)) {
StringBuilder sb = new StringBuilder();
sb.append(ColorUtils.redError("pageSize is not a number")).append(StringUtils.lineSeparator);
sb.append(ColorUtils.blackBold("detail usage please enter: help list"));
sb.append(ColorUtils.blackBold("detail usage please enter: help command"));
System.out.println(sb);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ public boolean supports(ProcessContext context) {
@Override
public void handle(ProcessContext context) {
TelProcessContext telProcessContext = (TelProcessContext) context;
String imeiListString = context.getData().substring(context.getData().indexOf(" ") + 1);
String[] arr = context.getData().split(" ");
if (arr.length < 2) {
StringBuilder sb = new StringBuilder();
sb.append(ColorUtils.redError("imei is required")).append(StringUtils.lineSeparator);
sb.append(ColorUtils.blackBold("detail usage please enter: help del"));
System.out.println(sb);
return;
}
String imeiListString = arr[2];
if (StringUtils.isNotBlank(imeiListString)) {
List<String> imeiList = List.of(imeiListString.split(","));
TelDelDeviceByImeiResponse response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void handle(ProcessContext context) {
break;
case "log":
sb.append(ColorUtils.colorBold("Usage: ", "black")
+ String.format("> %s %s <imei> [%s <name>] [%s] [%s <imsi>]",
+ String.format("> %s %s <imei> [%s <name>] [%s <startTime>] [%s <endTime>] %s",
ColorUtils.colorBold("log", "green"),
ColorUtils.colorBold("-imei", "green"),
ColorUtils.colorBold("-limit", "green"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import iot.technology.client.toolkit.common.rule.ProcessContext;
import iot.technology.client.toolkit.common.rule.TkProcessor;
import iot.technology.client.toolkit.common.utils.ColorUtils;
import iot.technology.client.toolkit.common.utils.StringUtils;
import iot.technology.client.toolkit.nb.service.processor.TelProcessContext;
import iot.technology.client.toolkit.nb.service.telecom.TelecomDeviceService;
Expand All @@ -38,7 +39,15 @@ public boolean supports(ProcessContext context) {

@Override
public void handle(ProcessContext context) {
String imei = context.getData().substring(context.getData().indexOf(" ") + 1);
String[] arr = context.getData().split(" ");
if (arr.length < 2) {
StringBuilder sb = new StringBuilder();
sb.append(ColorUtils.redError("imei is required")).append(StringUtils.lineSeparator);
sb.append(ColorUtils.blackBold("detail usage please enter: help show"));
System.out.println(sb);
return;
}
String imei = arr[2];
TelProcessContext telProcessContext = (TelProcessContext) context;
if (StringUtils.isNotBlank(imei)) {
TelQueryDeviceByImeiResponse response =
Expand Down
Loading