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

main.cpp

Committer:
lester0507
Date:
2015-10-13
Revision:
2:02d26be97892
Parent:
1:1571d6a1cb27
Child:
4:b419c498752b

File content as of revision 2:02d26be97892:

#include "mbed.h"
#include "MXmppClient.hpp"
#include "WIFIDevice.h"

#define SSID "LesterAP"
#define AP_PASSWORD "0225536029"

#define USER_NAME1 "nnn40b"
#define DOMAIN "xmpp.koryo.com.tw"
#define PASSWORD1 "123456"

#define USER_NAME2 "app2"

WIFIDevice wifi;
MxmppClient mXmppClient(USER_NAME1,DOMAIN,PASSWORD1,5222);
void onGetMessage(const char*);

DigitalOut led1(p7);
DigitalOut led2(p13);

int main(void)
{
    //set given SSID and PW as the highest priority
    wifi.setNetwork(SSID, AP_PASSWORD, 0);
   
    mXmppClient.login();
    if(mXmppClient.isLogin()) {
        mXmppClient.sendMessageToClient(USER_NAME2,"Login to XMPP server");
    }
    while(true) {
        mXmppClient.setMessageTracker(onGetMessage);
    }
}

void onGetMessage(const char *msg)
{
    if(strcmp(msg,"turn on")==0) {
        mXmppClient.sendMessageToClient(USER_NAME2,"The lights is on");
        led1=1;
        led2=1;
    } else if(strcmp(msg,"turn off")==0) {
        mXmppClient.sendMessageToClient(USER_NAME2,"The lights is off");
        led1=0;
        led2=0;
    } 
}