NNN40 XmppClient first commit

Dependencies:   WIFI_API_32kRAM mbed

How to use Demo code

  • Step1: Create Accounts, the accounts information as follow, (Demo server used Openfire3.9.3)
  1. Server Address: xmpp.koryo.com.tw
  2. Account1's name and password (nnn40b/123456)
  3. Account2's name and password (app2/123456)
  • Step2: Burn demo code to NNN40 module.

You can drag and drop the sample code to NNN40 module.

  • Step3: Login XMPP client by mobile or PC side.

Our demonstration is presented in Android phone, and we install ”Xabber” application for XMPP client login. We use “app2” account to login “xmpp.koryo.com.tw” server.

  • Step4: Login XMPP client by NNN40 module.

After turning on NNN40 module, the module will login to XMPP automatically. In addition, the module also sends a message to name2.

  • Step5: Turn on or turn off LED

you can chat with module and ask module to turn on or turn off LED.

How to install Openfire (XMPP Server)

If you want setup XMPP server by yourself, the Installation Guide as follow:

https://www.igniterealtime.org/builds/openfire/docs/latest/documentation/install-guide.html

the download link as follow (Openfire3.9.3):

http://www.igniterealtime.org/downloads/download-landing.jsp?file=openfire/openfire_3_9_3.exe

DEMO video

Committer:
lester0507
Date:
Tue Oct 13 06:39:55 2015 +0000
Revision:
4:b419c498752b
Parent:
2:02d26be97892
update SSID and Password

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lester0507 0:464110a4a6f1 1 #include "mbed.h"
lester0507 0:464110a4a6f1 2 #include "MXmppClient.hpp"
lester0507 0:464110a4a6f1 3 #include "WIFIDevice.h"
lester0507 0:464110a4a6f1 4
lester0507 4:b419c498752b 5 #define SSID "SSID"
lester0507 4:b419c498752b 6 #define AP_PASSWORD "0123456789"
lester0507 0:464110a4a6f1 7
lester0507 2:02d26be97892 8 #define USER_NAME1 "nnn40b"
lester0507 2:02d26be97892 9 #define DOMAIN "xmpp.koryo.com.tw"
lester0507 2:02d26be97892 10 #define PASSWORD1 "123456"
lester0507 0:464110a4a6f1 11
lester0507 2:02d26be97892 12 #define USER_NAME2 "app2"
lester0507 0:464110a4a6f1 13
lester0507 0:464110a4a6f1 14 WIFIDevice wifi;
lester0507 0:464110a4a6f1 15 MxmppClient mXmppClient(USER_NAME1,DOMAIN,PASSWORD1,5222);
lester0507 0:464110a4a6f1 16 void onGetMessage(const char*);
lester0507 0:464110a4a6f1 17
lester0507 0:464110a4a6f1 18 DigitalOut led1(p7);
lester0507 1:1571d6a1cb27 19 DigitalOut led2(p13);
lester0507 0:464110a4a6f1 20
lester0507 0:464110a4a6f1 21 int main(void)
lester0507 0:464110a4a6f1 22 {
lester0507 0:464110a4a6f1 23 //set given SSID and PW as the highest priority
lester0507 0:464110a4a6f1 24 wifi.setNetwork(SSID, AP_PASSWORD, 0);
lester0507 0:464110a4a6f1 25
lester0507 0:464110a4a6f1 26 mXmppClient.login();
lester0507 0:464110a4a6f1 27 if(mXmppClient.isLogin()) {
lester0507 0:464110a4a6f1 28 mXmppClient.sendMessageToClient(USER_NAME2,"Login to XMPP server");
lester0507 0:464110a4a6f1 29 }
lester0507 0:464110a4a6f1 30 while(true) {
lester0507 0:464110a4a6f1 31 mXmppClient.setMessageTracker(onGetMessage);
lester0507 0:464110a4a6f1 32 }
lester0507 0:464110a4a6f1 33 }
lester0507 0:464110a4a6f1 34
lester0507 0:464110a4a6f1 35 void onGetMessage(const char *msg)
lester0507 0:464110a4a6f1 36 {
lester0507 0:464110a4a6f1 37 if(strcmp(msg,"turn on")==0) {
lester0507 0:464110a4a6f1 38 mXmppClient.sendMessageToClient(USER_NAME2,"The lights is on");
lester0507 0:464110a4a6f1 39 led1=1;
lester0507 1:1571d6a1cb27 40 led2=1;
lester0507 0:464110a4a6f1 41 } else if(strcmp(msg,"turn off")==0) {
lester0507 0:464110a4a6f1 42 mXmppClient.sendMessageToClient(USER_NAME2,"The lights is off");
lester0507 0:464110a4a6f1 43 led1=0;
lester0507 1:1571d6a1cb27 44 led2=0;
lester0507 0:464110a4a6f1 45 }
lester0507 0:464110a4a6f1 46 }