ThingPlug Test
Dependents: WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P
Fork of WizFi310Interface by
Revision 7:b7019399eb1e, committed 2017-08-25
- Comitter:
- cliff1
- Date:
- Fri Aug 25 00:55:43 2017 +0000
- Parent:
- 2:04c8d61984a3
- Child:
- 8:08588dd2a66f
- Commit message:
- 20170825 ThingPlug
Changed in this revision
--- a/WizFi310/WizFi310.cpp Mon Apr 10 09:54:34 2017 +0000
+++ b/WizFi310/WizFi310.cpp Fri Aug 25 00:55:43 2017 +0000
@@ -167,3 +167,25 @@
return _state.mac;
}
+
+int WizFi310::joinTP(const char *clientId, const char *credentialId, const char *serviceId, const char *devId, const char *containerNm)
+{
+ WIZ_INFO("ThingPlug Start\r\n");
+
+ if(cmdSKTPCON("1", clientId, credentialId, serviceId, devId)) return -1;
+ WIZ_INFO("ThingPlug Connected");
+
+ if(cmdSKTPDEVICE("1", devId)) return -1;
+ WIZ_INFO("Device Registered");
+
+ if(cmdSKTPCONTAINER("1", containerNm)) return -1;
+ WIZ_INFO("Created Container");
+
+ if(cmdSKTPSEND(containerNm, "010600000026020600000022")) return -1;
+ WIZ_INFO("Sending Data");
+
+ if(cmdSKTPCON("0", clientId, credentialId, serviceId, devId)) return -1;
+ WIZ_INFO("ThingPlug Disconnected");
+
+ return 0;
+}
\ No newline at end of file
--- a/WizFi310/WizFi310.h Mon Apr 10 09:54:34 2017 +0000
+++ b/WizFi310/WizFi310.h Fri Aug 25 00:55:43 2017 +0000
@@ -146,6 +146,15 @@
int cmdCLOSE ( int cid );
int cmdFDNS (const char *host);
int cmdSMGMT ( int cid );
+
+
+ int cmdSKTPCON (const char *openType);
+ int cmdSKTPCON (const char *openType, const char *clientId, const char *credentialId, const char *serviceId, const char *devId);
+ int cmdSKTPDEVICE (const char *openType, const char *devId);
+ int cmdSKTPCONTAINER (const char *openType, const char *containerName);
+ int cmdSKTPCMD (const char *openType, const char *commandName);
+ int cmdSKTPSEND (const char *containerName, const char *sendData);
+ int cmdSKTPRESULT ();
static WizFi310 * getInstance() {
@@ -259,6 +268,10 @@
const char* getIPAddress (void);
const char* getMACAddress (void);
+
+
+ int joinTP (const char *clientId, const char *credentialId, const char *serviceId, const char *devId, const char *containerNm);
+
// --------- WizFi250_msg.cpp ---------
void recvData ( char c );
@@ -280,6 +293,7 @@
void resSMGMT (const char *buf);
void resWSTATUS (const char *buf);
+ void resSKTPCON (const char *buf);
// --------- WizFi250_hal.cpp ---------
void setReset (bool flg);
--- a/WizFi310/WizFi310_at.cpp Mon Apr 10 09:54:34 2017 +0000
+++ b/WizFi310/WizFi310_at.cpp Fri Aug 25 00:55:43 2017 +0000
@@ -344,3 +344,75 @@
resp = sendCommand("AT+SMGMT=?", RES_SMGMT);
return resp;
}
+
+
+int WizFi310::cmdSKTPCON ( const char *openType )
+{
+ char cmd[CFG_CMD_SIZE];
+ int resp;
+
+ sprintf(cmd,"AT+SKTPCON=%s", openType);
+ resp = sendCommand(cmd);
+
+ return resp;
+}
+
+int WizFi310::cmdSKTPCON ( const char *openType, const char *clientId, const char *credentialId, const char *serviceId, const char *devId )
+{
+ char cmd[CFG_CMD_SIZE];
+ int resp;
+
+ sprintf(cmd,"AT+SKTPCON=%s,mqtt.thingplug.net,1883,300,%s,%s,%s,v1_0,%s", openType, clientId, credentialId, serviceId, devId);
+ resp = sendCommand(cmd);
+
+ return resp;
+}
+
+int WizFi310::cmdSKTPDEVICE (const char *openType, const char *devId)
+{
+ char cmd[CFG_CMD_SIZE];
+ int resp;
+
+ sprintf(cmd,"AT+SKTPDEVICE=%s,%s", openType, devId);
+ resp = sendCommand(cmd);
+
+ return resp;
+}
+
+int WizFi310::cmdSKTPCONTAINER ( const char *openType, const char *containerName )
+{
+ char cmd[CFG_CMD_SIZE];
+ int resp;
+
+ sprintf(cmd,"AT+SKTPCONTAINER=%s,%s", openType, containerName);
+ resp = sendCommand(cmd);
+ return resp;
+}
+
+int WizFi310::cmdSKTPCMD ( const char *openType, const char *commandName )
+{
+ char cmd[CFG_CMD_SIZE];
+ int resp;
+
+ sprintf(cmd,"AT+SKTPCMD=%s,%s", openType, commandName);
+ resp = sendCommand(cmd);
+ return resp;
+}
+
+int WizFi310::cmdSKTPSEND ( const char *containerName, const char *sendData )
+{
+ char cmd[CFG_CMD_SIZE];
+ int resp;
+
+ sprintf(cmd,"AT+SKTPSEND=%s,%s", containerName, sendData);
+ resp = sendCommand(cmd);
+ return resp;
+}
+
+int WizFi310::cmdSKTPRESULT ( )
+{
+ int resp;
+
+ resp = sendCommand("AT+SKTPRESULT=?", RES_SMGMT);
+ return resp;
+}
\ No newline at end of file
--- a/WizFi310/WizFi310_conf.h Mon Apr 10 09:54:34 2017 +0000 +++ b/WizFi310/WizFi310_conf.h Fri Aug 25 00:55:43 2017 +0000 @@ -28,7 +28,7 @@ #define DEFAULT_WAIT_RESP_TIMEOUT 2000 // ms #define CFG_JOIN_TIMEOUT 60000 // ms -#define CFG_CMD_SIZE 128 +#define CFG_CMD_SIZE 256 #define CFG_DATA_SIZE BUF_SIZE
--- a/WizFi310Interface.cpp Mon Apr 10 09:54:34 2017 +0000
+++ b/WizFi310Interface.cpp Fri Aug 25 00:55:43 2017 +0000
@@ -72,6 +72,38 @@
return _wizfi310.getMACAddress();
}
+int WizFi310Interface::conTP(const char *clientId, const char *credentialId, const char *serviceId, const char *devId, const char *containerNm)
+{
+ //if ( _wizfi310.joinTP(clientId, credentialId, serviceId, devId, containerNm) == -1 ) return NSAPI_ERROR_NO_SOCKET;
+
+ if(_wizfi310.cmdSKTPCON("1", clientId, credentialId, serviceId, devId)) return -1;
+ WIZ_INFO("ThingPlug Connected");
+
+ if(_wizfi310.cmdSKTPDEVICE("1", devId)) return -1;
+ WIZ_INFO("Device Registered");
+
+ if(_wizfi310.cmdSKTPCONTAINER("1", containerNm)) return -1;
+ WIZ_INFO("Created Container\r\n");
+
+ return 0;
+}
+
+int WizFi310Interface::sendTP(const char *containerNm, const char *sendData)
+{
+ if(_wizfi310.cmdSKTPSEND(containerNm, sendData)) return -1;
+ WIZ_INFO("Data sent\r\n");
+
+ return 0;
+}
+
+int WizFi310Interface::disConTP()
+{
+ if(_wizfi310.cmdSKTPCON("0")) return -1;
+ WIZ_INFO("ThingPlug Disconnected\r\n");
+
+ return 0;
+}
+
struct wizfi310_socket {
int id;
nsapi_protocol_t proto;
--- a/WizFi310Interface.h Mon Apr 10 09:54:34 2017 +0000
+++ b/WizFi310Interface.h Fri Aug 25 00:55:43 2017 +0000
@@ -55,6 +55,11 @@
virtual const char *get_mac_address();
+ virtual int conTP(const char *clientId, const char *credentialId, const char *serviceId, const char *devId, const char *containerNm);
+ virtual int sendTP(const char *containerNm, const char *sendData);
+ virtual int disConTP();
+
+
WizFi310* get_WizFi310_Pointer()
{
return &_wizfi310;
