本文在前一篇基础上,详细介绍以CrossApp跨平台框架为基础,利用mosquito库和easySQLite库设计实现了基于MQTT协议的android版步进电机控制客户端。

一、开发环境的准备

编译环境为CrossApp平台提供的一键部署windows下android开发环境的工具包:
下载地址:
http://pan.baidu.com/s/1qW6ql32#dir/path=%2FCrossApp-Ide

工具包的安装在此省略。参考文章:
https://www.oschina.net/question/1271569_160671

一步步按照向导设置好自己的软件环境。我安装的是x64版。

二、工程的构建和基本设置

安装好后,运行C:\CrossApp\eclipse下的eclipse.exe

参考:http://blog.csdn.net/j2066/article/details/47624109

菜单->file->new->other

然后next,选对相应的android工程:

导入成功后看到:

看到前面左下角有个红色的叉,这是因为框架代码没有导入进来。
接着,按照前面的方法导入CrossApp框架代码工程:

然后看到有错误提示:

[2017-10-02 20:09:21 - StepMotorController] Unable to resolve target 'android-20'
[2017-10-02 20:14:47 - libCrossApp] Unable to resolve target 'android-20'
[2017-10-02 20:14:49 - libCrossApp] Unable to resolve target 'android-20'

需要修改libCrossApp的属性。
对着libCrossApp点右键,选Properties(属性):

在Project Build Target中选Android 4.4.2:

对于StepMotorController项目也一样设置这个地方:

接着,我们需要修改一下StepMotorController项目下的make文件:
双击项目下的jni下的Android.mk文件:

需要修改这个地方:

为去掉注释符号:

$(call import-add-path, $(LOCAL_PATH)/../../../..)
$(call import-add-path, $(LOCAL_PATH)/../../../../CrossApp/the_third_party/)

先编译一下,右击项目,Run As->Android Application:

看到命令行有个错误:

这个错误是本项目的NDK构建环境android-ndk-r9路径设置有问题造成的:
右键点StepMotorController属性(Properties)->c/c++ Build->Environment->NDK ROOT:

双击这一行,把NDK ROOT设置为自己的路径,我们装包默认的是C:\CrossApp\android-ndk-r9d:

点OK:

还有一个地方需要修改:

修改为我们安装的目录:
C:\CrossApp\android-ndk-r9d\ndk-build.cmd

点OK,编译一下,看到一条错误:

jni/../../Classes/easySQLite/SqlCommon.h:136:22: error: format not a string literal and no format arguments [-Werror=format-security]

参考网上文章,原因是:

  android-ndk-r9与Eclipse的版本不兼容问题

解决方法:

  在对应项目的proj.android/jni/Application.mk添加一句话

  APP_CFLAGS += -Wno-error=format-security

  意思就是无视这个error
  

再次编译,又出来错误:

jni/../../Classes/MenuViewController.cpp:105:15: error: converting to execution character set: Illegal byte sequence

这个错误原因是MenuViewController.cpp这个文件的文本格式是ANSI,因为不是支持unicode的格式,所以,不支持中文编码。
解决这个问题的方法是,用记事本打开这个文件另存为UTF-8格式:

编译一下,又出现错误:

jni/../../Classes/easySQLite/SqlCommon.cpp: In member function 'sql::string sql::time::format(const char*)':
jni/../../Classes/easySQLite/SqlCommon.cpp:70:38: error: 'localtime_s' was not declared in this scopeif (localtime_s(&localtime, &_value) == 0)^
jni/../../Classes/easySQLite/SqlCommon.cpp: In function 'sql::string sql::intToStr(int)':
jni/../../Classes/easySQLite/SqlCommon.cpp:116:43: error: '_itoa_s' was not declared in this scope_itoa_s(value, buffer, sizeof(buffer), 10);^
jni/../../Classes/easySQLite/SqlCommon.cpp: In function 'sql::string sql::intToStr(sql::integer)':
jni/../../Classes/easySQLite/SqlCommon.cpp:123:45: error: '_i64toa_s' was not declared in this scope_i64toa_s(value, buffer, sizeof(buffer), 10);^
make.exe: *** [obj/local/armeabi/objs/CrossApp_cpp_shared/__/__/Classes/easySQLite/SqlCommon.o] Error 1

这些错误的原因是我们目前使用的easySQLite库版本太老了,g++编译器(ndk用的是4.8)对这些函数不支持,解决方法是下载一个更新一点的版本来替换原库。这个版本是cocos-2dx引擎提供的:
https://github.com/gelldur/easysqlite

下载下来,把easysqlite-master.zip\easysqlite-master\easySQLite中所有原代码替换原库中的对应文件,然后重新编译。
然后出现一堆错误:

jni/../../Classes/MQTT/mosquittopp.cpp:123: error: undefined reference to 'mosquitto_destroy'
jni/../../Classes/MQTT/mosquittopp.cpp:76: error: undefined reference to 'mosquitto_lib_init'
jni/../../Classes/MQTT/mosquittopp.cpp:81: error: undefined reference to 'mosquitto_lib_cleanup'
jni/../../Classes/MQTT/mosquittopp.cpp:86: error: undefined reference to 'mosquitto_strerror'
jni/../../Classes/MQTT/mosquittopp.cpp:91: error: undefined reference to 'mosquitto_connack_string'
jni/../../Classes/MQTT/mosquittopp.cpp:96: error: undefined reference to 'mosquitto_sub_topic_tokenise'
jni/../../Classes/MQTT/mosquittopp.cpp:101: error: undefined reference to 'mosquitto_sub_topic_tokens_free'
jni/../../Classes/MQTT/mosquittopp.cpp:106: error: undefined reference to 'mosquitto_topic_matches_sub'
jni/../../Classes/MQTT/mosquittopp.cpp:111: error: undefined reference to 'mosquitto_new'
jni/../../Classes/MQTT/mosquittopp.cpp:112: error: undefined reference to 'mosquitto_connect_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:113: error: undefined reference to 'mosquitto_disconnect_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:114: error: undefined reference to 'mosquitto_publish_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:115: error: undefined reference to 'mosquitto_message_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:116: error: undefined reference to 'mosquitto_subscribe_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:117: error: undefined reference to 'mosquitto_unsubscribe_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:118: error: undefined reference to 'mosquitto_log_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:129: error: undefined reference to 'mosquitto_reinitialise'
jni/../../Classes/MQTT/mosquittopp.cpp:131: error: undefined reference to 'mosquitto_connect_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:132: error: undefined reference to 'mosquitto_disconnect_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:133: error: undefined reference to 'mosquitto_publish_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:134: error: undefined reference to 'mosquitto_message_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:135: error: undefined reference to 'mosquitto_subscribe_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:136: error: undefined reference to 'mosquitto_unsubscribe_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:137: error: undefined reference to 'mosquitto_log_callback_set'
jni/../../Classes/MQTT/mosquittopp.cpp:144: error: undefined reference to 'mosquitto_connect'
jni/../../Classes/MQTT/mosquittopp.cpp:149: error: undefined reference to 'mosquitto_connect_bind'
jni/../../Classes/MQTT/mosquittopp.cpp:154: error: undefined reference to 'mosquitto_connect_async'
jni/../../Classes/MQTT/mosquittopp.cpp:159: error: undefined reference to 'mosquitto_connect_bind_async'
jni/../../Classes/MQTT/mosquittopp.cpp:164: error: undefined reference to 'mosquitto_reconnect'
jni/../../Classes/MQTT/mosquittopp.cpp:169: error: undefined reference to 'mosquitto_reconnect_async'
jni/../../Classes/MQTT/mosquittopp.cpp:174: error: undefined reference to 'mosquitto_disconnect'
jni/../../Classes/MQTT/mosquittopp.cpp:179: error: undefined reference to 'mosquitto_socket'
jni/../../Classes/MQTT/mosquittopp.cpp:184: error: undefined reference to 'mosquitto_will_set'
jni/../../Classes/MQTT/mosquittopp.cpp:189: error: undefined reference to 'mosquitto_will_clear'
jni/../../Classes/MQTT/mosquittopp.cpp:194: error: undefined reference to 'mosquitto_username_pw_set'
jni/../../Classes/MQTT/mosquittopp.cpp:199: error: undefined reference to 'mosquitto_publish'
jni/../../Classes/MQTT/mosquittopp.cpp:204: error: undefined reference to 'mosquitto_reconnect_delay_set'
jni/../../Classes/MQTT/mosquittopp.cpp:209: error: undefined reference to 'mosquitto_max_inflight_messages_set'
jni/../../Classes/MQTT/mosquittopp.cpp:214: error: undefined reference to 'mosquitto_message_retry_set'
jni/../../Classes/MQTT/mosquittopp.cpp:219: error: undefined reference to 'mosquitto_subscribe'
jni/../../Classes/MQTT/mosquittopp.cpp:224: error: undefined reference to 'mosquitto_unsubscribe'
jni/../../Classes/MQTT/mosquittopp.cpp:229: error: undefined reference to 'mosquitto_loop'
jni/../../Classes/MQTT/mosquittopp.cpp:234: error: undefined reference to 'mosquitto_loop_misc'
jni/../../Classes/MQTT/mosquittopp.cpp:239: error: undefined reference to 'mosquitto_loop_read'
jni/../../Classes/MQTT/mosquittopp.cpp:244: error: undefined reference to 'mosquitto_loop_write'
jni/../../Classes/MQTT/mosquittopp.cpp:249: error: undefined reference to 'mosquitto_loop_forever'
jni/../../Classes/MQTT/mosquittopp.cpp:254: error: undefined reference to 'mosquitto_loop_start'
jni/../../Classes/MQTT/mosquittopp.cpp:259: error: undefined reference to 'mosquitto_loop_stop'
jni/../../Classes/MQTT/mosquittopp.cpp:264: error: undefined reference to 'mosquitto_want_write'
jni/../../Classes/MQTT/mosquittopp.cpp:269: error: undefined reference to 'mosquitto_opts_set'
jni/../../Classes/MQTT/mosquittopp.cpp:274: error: undefined reference to 'mosquitto_threaded_set'
jni/../../Classes/MQTT/mosquittopp.cpp:279: error: undefined reference to 'mosquitto_user_data_set'
jni/../../Classes/MQTT/mosquittopp.cpp:294: error: undefined reference to 'mosquitto_tls_set'
jni/../../Classes/MQTT/mosquittopp.cpp:299: error: undefined reference to 'mosquitto_tls_opts_set'
jni/../../Classes/MQTT/mosquittopp.cpp:304: error: undefined reference to 'mosquitto_tls_insecure_set'
jni/../../Classes/MQTT/mosquittopp.cpp:309: error: undefined reference to 'mosquitto_tls_psk_set'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libCrossApp_cpp.so] Error 1

这些错误原因,是没有把mosquitto的源代码编译进去,为什么没有编译进去呢?这需要看makefile是怎么写的。看android.mk中有这么 一行:

MY_FILES_SUFFIX := %.cpp

这是指定文件后缀为.cpp,也就是只搜索项目中的cpp文件,而不搜集c文件,在它后面加上%.c以支持编译c文件:

MY_FILES_SUFFIX := %.cpp %.c

再编译可以看到mosquitto源代码已经编译进去了,但看到一堆错误:

C:/CrossApp/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: ./obj/local/armeabi/libCrossApp.a(sqlite3.o): multiple definition of 'sqlite3_compileoption_get'
C:/CrossApp/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/CrossApp_cpp_shared/__/__/Classes/easySQLite/sqlite3.o: previous definition here......C:/CrossApp/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/CrossApp_cpp_shared/__/__/Classes/easySQLite/sqlite3.o: previous definition here
jni/../../Classes/MQTT/mosquitto.c:282: error: undefined reference to 'pthread_cancel'
jni/../../Classes/MQTT/thread_mosq.c:66: error: undefined reference to 'pthread_cancel'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libCrossApp_cpp.so] Error 1

这一堆的错误,主要是有两个:
1、sqlite3这个目标文件已经在CrossApp链接过了,所以,这里提示重复定义;
2、mosquitto.c、thread_mosq.c所使用的pthread_cancel这个poxis函数,在android的ndk平台不支持。

对于第一个错误,需要修改android.mk,在编译时,过滤掉sqlite3.c文件。把

LOCAL_SRC_FILES  := $(MY_SRC_LIST)

修改为:

LOCAL_SRC_FILES  := $(filter-out %/sqlite3.c,$(MY_SRC_LIST)) #don't compile sqlite3.c ,becase it has been contained in the CrossApp core lib . #$(MY_SRC_LIST)

意思是从MY_SRC_LIST所包含的文件中过滤掉所有的sqlite3.c文件,当然实际上只有一个。
重新编译链接,可以看到剩下二个错误:

jni/../../Classes/MQTT/mosquitto.c:282: error: undefined reference to 'pthread_cancel'
jni/../../Classes/MQTT/thread_mosq.c:66: error: undefined reference to 'pthread_cancel'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libCrossApp_cpp.so] Error 1

需要修改mosquitto.c、thread_mosq.c。

对于这一部分,参考网上的解决方案,使用了pthread_kill来代替pthread_cancel,至于有没有什么不妥,就可能不好说了。目前先这样解决。
nano-CrossApp\projects\StepMotorController\Classes\MQTT\mosquitto.c中的
void _mosquitto_destroy(struct mosquitto *mosq)函数修改部分如下:

红色的部分是需要添加的。

#include "platform/CCPlatformConfig.h"void _mosquitto_destroy(struct mosquitto *mosq)
{struct _mosquitto_packet *packet;if(!mosq) return;#ifdef WITH_THREADINGif(mosq->threaded == mosq_ts_self && !pthread_equal(mosq->thread_id, pthread_self())){
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)//if ( (ESRCH= = pthread_kill(mosq->thread_id, SIGUSR1))) //{ //  printf("Error cancelling thread %d, error = %d (%s)", pthread_id, status, strerror status));//} if(pthread_kill(mosq->thread_id, 0)!= ESRCH){//printf("thread %d exists!\n", pid);pthread_kill(mosq->thread_id, SIGQUIT);//printf("after kill\n");}
#else pthread_cancel(mosq->thread_id);#endifpthread_join(mosq->thread_id, NULL);mosq->threaded = mosq_ts_none;}if(mosq->id){/* If mosq->id is not NULL then the client has already been initialised* and so the mutexes need destroying. If mosq->id is NULL, the mutexes* haven't been initialised. */pthread_mutex_destroy(&mosq->callback_mutex);pthread_mutex_destroy(&mosq->log_callback_mutex);pthread_mutex_destroy(&mosq->state_mutex);pthread_mutex_destroy(&mosq->out_packet_mutex);pthread_mutex_destroy(&mosq->current_out_packet_mutex);pthread_mutex_destroy(&mosq->msgtime_mutex);pthread_mutex_destroy(&mosq->in_message_mutex);pthread_mutex_destroy(&mosq->out_message_mutex);pthread_mutex_destroy(&mosq->mid_mutex);}
#endifif(mosq->sock != INVALID_SOCKET){_mosquitto_socket_close(mosq);}_mosquitto_message_cleanup_all(mosq);_mosquitto_will_clear(mosq);
#ifdef WITH_TLSif(mosq->ssl){SSL_free(mosq->ssl);}if(mosq->ssl_ctx){SSL_CTX_free(mosq->ssl_ctx);}if(mosq->tls_cafile) _mosquitto_free(mosq->tls_cafile);if(mosq->tls_capath) _mosquitto_free(mosq->tls_capath);if(mosq->tls_certfile) _mosquitto_free(mosq->tls_certfile);if(mosq->tls_keyfile) _mosquitto_free(mosq->tls_keyfile);if(mosq->tls_pw_callback) mosq->tls_pw_callback = NULL;if(mosq->tls_version) _mosquitto_free(mosq->tls_version);if(mosq->tls_ciphers) _mosquitto_free(mosq->tls_ciphers);if(mosq->tls_psk) _mosquitto_free(mosq->tls_psk);if(mosq->tls_psk_identity) _mosquitto_free(mosq->tls_psk_identity);
#endifif(mosq->address){_mosquitto_free(mosq->address);mosq->address = NULL;}if(mosq->id){_mosquitto_free(mosq->id);mosq->id = NULL;}if(mosq->username){_mosquitto_free(mosq->username);mosq->username = NULL;}if(mosq->password){_mosquitto_free(mosq->password);mosq->password = NULL;}if(mosq->host){_mosquitto_free(mosq->host);mosq->host = NULL;}if(mosq->bind_address){_mosquitto_free(mosq->bind_address);mosq->bind_address = NULL;}/* Out packet cleanup */if(mosq->out_packet && !mosq->current_out_packet){mosq->current_out_packet = mosq->out_packet;mosq->out_packet = mosq->out_packet->next;}while(mosq->current_out_packet){packet = mosq->current_out_packet;/* Free data and reset values */mosq->current_out_packet = mosq->out_packet;if(mosq->out_packet){mosq->out_packet = mosq->out_packet->next;}_mosquitto_packet_cleanup(packet);_mosquitto_free(packet);}_mosquitto_packet_cleanup(&mosq->in_packet);if(mosq->sockpairR != INVALID_SOCKET){COMPAT_CLOSE(mosq->sockpairR);mosq->sockpairR = INVALID_SOCKET;}if(mosq->sockpairW != INVALID_SOCKET){COMPAT_CLOSE(mosq->sockpairW);mosq->sockpairW = INVALID_SOCKET;}
}

第二个、
对于nano-CrossApp\projects\StepMotorController\Classes\MQTT\thread_mosq.c中的
int mosquitto_loop_stop(struct mosquitto *mosq, bool force)函数修改如下:

#include <errno.h>
#include "platform/CCPlatformConfig.h"int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
{
#ifdef WITH_THREADING
#  ifndef WITH_BROKERchar sockpair_data = 0;
#  endifif(!mosq || mosq->threaded != mosq_ts_self) return MOSQ_ERR_INVAL;/* Write a single byte to sockpairW (connected to sockpairR) to break out* of select() if in threaded mode. */if(mosq->sockpairW != INVALID_SOCKET){
#ifndef WIN32if(write(mosq->sockpairW, &sockpair_data, 1)){}
#elsesend(mosq->sockpairW, &sockpair_data, 1, 0);
#endif}if(force){
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)//if ( (ESRCH= = pthread_kill(mosq->thread_id, SIGUSR1))) //{ //  printf("Error cancelling thread %d, error = %d (%s)", pthread_id, status, strerror status));//} if(pthread_kill(mosq->thread_id, 0)!= ESRCH){//printf("thread %d exists!\n", pid);pthread_kill(mosq->thread_id, SIGQUIT);//printf("after kill\n");}
#else pthread_cancel(mosq->thread_id);#endif}pthread_join(mosq->thread_id, NULL);mosq->thread_id = pthread_self();mosq->threaded = mosq_ts_none;return MOSQ_ERR_SUCCESS;
#elsereturn MOSQ_ERR_NOT_SUPPORTED;
#endif
}

修改之后,重新编译链接,ok。

三、验证一下android版对MQTT broker的连接功能

然后接上手机(安卓系统,我的版本是4.4.4):

这里是还没对broker的参数进行设置,需要设置一下server ip,一般情况下,可以使用wifi在同一个局域网下连接服务器了。但是因为我使用的wifi是在台式机接的360随身wifi,因此,没别的办法,只能从外网来连接我台式机了。
所以,需要在路由上做ip映射。

我的路由是水星MAC1200R,进入路由设置界面,点右上角的高级设置,然后点开左边菜单高级用户,点虚拟服务器,看到如下界面:

然后点那个加号添加:

在常用服务器中选SOCK,外部端口和内部端口都填1883,ip地址填要映射到的台式机IP,我的是10.0.0.108,协议类型可以默认,为ALL,填完之后,点最右边保存。
这样就ok了。

下面查看一下公网IP,点右上角常用设置,然后左边菜单点上网设置,可以看到IP地址:

这个IP地址:123.xxx.xxx.xxx就是我们宽带的公网IP,也就是我们需要在手机号上填写的IP地址。这样,当我们连该IP的时候,路由就把该连接映射到我台式机上了。
下面系列图片是在手机上的操作:

可以看到这里出现了bug!

继续:

但保存之后,返回主界面,又出现了bug:连接的时候,没有使用新设置的IP地址。

以上第一个bug是布局格式选得不合适。

关于CrossApp布局格式的参数的意义请参考:
https://www.w3cschool.cn/crossapp/rv2g1pw1.html

对布局的设置在void SettingsViewController::viewDidLoad()函数中,经过测试,用比例的方式来布局,相关参数适合设置(我测试的手机是三星i9100 galaxy s2,主屏分辨率:800x480像素)如下:

void SettingsViewController::viewDidLoad()
{CAImageView* view1 = CAImageView::createWithImage(CAImage::create("image/motor_control_view.jpg"));view1->setLayout(DLayoutFill);this->getView()->addSubview(view1);CALabel* label = CALabel::create();label->setColor(ccc4(51, 204, 255, 255));label->setText( UTF8( "网络参数设置"));label->setFontSize(36);label->setTextAlignment(CATextAlignmentLeft);label->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);label->setLayout(DLayout(DHorizontalLayout_W_C(240, 0.5), DVerticalLayout_H_C(40, 0.12)));this->getView()->addSubview(label);std::string ctn;m_textField_IP = CATextField::createWithLayout(DLayout(DHorizontalLayout_W_C(400, 0.5), DVerticalLayout_H_C(70, 0.30)));m_textField_IP->setTag(200);//PlaceHolder文本内容ctn = "IP: " +m_NetworkInfo.getIP();m_textField_IP->setPlaceHolderText(ctn);//键盘类型m_textField_IP->setKeyboardType(CATextField::Default);//TextField的对齐方式m_textField_IP->setTextFieldAlign(CATextField::Left);m_textField_IP->setDelegate(this);this->getView()->addSubview(m_textField_IP);m_textField_Port = CATextField::createWithLayout(DLayout(DHorizontalLayout_W_C(400, 0.5), DVerticalLayout_H_C(70, 0.50)));m_textField_Port->setTag(201);//PlaceHolder文本内容char str[256];sprintf(str, "Port: %d", m_NetworkInfo.getPort());ctn = std::string(str);m_textField_Port->setPlaceHolderText(ctn);//键盘类型m_textField_Port->setKeyboardType(CATextField::Default);//TextField的对齐方式m_textField_Port->setTextFieldAlign(CATextField::Left);m_textField_Port->setDelegate(this);this->getView()->addSubview(m_textField_Port);//初始化viewListm_SaveBtn = CAButton::create(CAButtonTypeRoundedRect);m_SaveBtn->setLayout(DLayout(DHorizontalLayout_W_C(240, 0.5), DVerticalLayout_T_H(600, 100)));m_SaveBtn->setTag(203);m_SaveBtn->setTitleFontSize(36);m_SaveBtn->setTitleForState(CAControlStateAll, UTF8("保存参数"));m_SaveBtn->addTarget(this, CAControl_selector(SettingsViewController::alertButtonCallBack), CAControlEventTouchUpInSide);this->getView()->addSubview(m_SaveBtn);}

修改之后,运行效果:

对于第二个bug,在
void StepMotorControlView::viewDidDisappear()函数最后,加入

    if (m_MQTTInstance){delete m_MQTTInstance;m_MQTTInstance = NULL;}

改后代码:

void StepMotorControlView::viewDidDisappear()
{if (m_MQTTInstance && m_MQTTInstance->IsHardwareStarted()){m_StepMotorHardware.setActionSate(0);SendActionMessage(m_StepMotorHardware.getIDX(), m_StepMotorHardware.getActionState(),m_StepMotorHardware.getDirection(),m_StepMotorHardware.getVelocity());m_MQTTInstance->StopHardware();}if (m_MQTTInstance){delete m_MQTTInstance;m_MQTTInstance = NULL;}
}

最后的连接效果:

四、联合开发板做测试

完整源代码:
StepMotorController_2017.10.03_VS2013 Android.rar

需要说明一下的是,这个版本因为兼容android做了一些修改,而修改后的代码也在VS2013上编译运行过,是可以的,因此,这一版支持了两个平台。

基于FreeRTOS与MQTT的物联网技术应用系列——步进电机控制(七)基于CrossApp跨平台框架的MQTT客户端控制应用android版相关推荐

  1. 基于FreeRTOS与MQTT的物联网技术应用系列——步进电机控制(一)前言

    一 .简介: 本应用主要是基于MQTT协议,开发一个能由PC或移动端(ios或android)控制嵌入式设备乃至处理反馈信息等功能的系统. 嵌入式设备的控制是基于FreeRTOS操作系统和本项目自行开 ...

  2. 基于FreeRTOS与MQTT的物联网技术应用系列——步进电机控制(四)FreeRTOS系统下LwIP-1.4.1的移植

    本文在前一篇的基础上,进行基于FreeRTOS的LwIP-1.4.1版本移植. 本文使用的网卡PHY芯片型号是DP83848,工作在MII接口模式,时钟频率是25MHz. 现在的LwIP版本已经发展到 ...

  3. 基于FreeRTOS与MQTT的物联网技术应用系列——步进电机控制(五)MQTT的移植和步进电机控制的实现

    本文在前一篇的基础上进行MQTT的移植,并实现对步进电机驱动器的控制. 分两步完成: 1.移植MQTT协议栈,并进行验证: 2.对步进电机进行控制. 一,移植MQTT协议 参考实现:https://g ...

  4. 【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境

    这是机器未来的第24篇文章 原文首发地址:https://blog.csdn.net/RobotFutures/article/details/125532208 1. mosquitto概述 Ecl ...

  5. 一个基于.Net Core 开源的物联网基础平台

    在智慧工厂领域,智慧城市领域,都需要对设备进行监控.比如工厂需要对周围环境温度.湿度.气压.电压,灯的开关进行监控.这时候就需要物联网平台来进行管理. 在智慧工厂领域,宝马集团通过英伟达的Omnive ...

  6. 大数据时代物联网技术发展前景与应用分析

    注:本文由音序为GD的童鞋原创,在此代为发表 摘要: 当前,以物联网.大数据和云计算为代表的新一代信息技术发展迅猛,目前正在由IT时代转向DT时代.物联网技术正在通过与其它新技术的不断融合,加速向智能 ...

  7. 解析EPCglobal物联网技术之ONS服务

    [摘要] ONS服务做为EPCglobal倡导的物联网框架中的重要一环,实现货品信息在全球范围内的定位和共享,本文将着重探讨ONS服务的技术原理,实现架构和应用前景. 引言 在EPCglobal提出的 ...

  8. 物联网技术NB-IOT的网络和应用场景

    物联网技术NB-IOT的网络和应用场景 NB-IoT的全称是Narrow Band-Internet of Things,是基于蜂窝网络的窄带物联网技术,聚焦于低功耗广域网,支持物联网设备在广域网的蜂 ...

  9. 《大数据》编辑推荐 | 基于遥感大数据的信息提取技术综述

    主题词 遥感大数据:目标识别:地物分割:变化检测 遥感大数据虽然能够多粒度.多时相.多方位和多层次地反映地物信息,但其数据量与日俱增.种类日益增多,且存在大量的冗余信息,使得从遥感数据中提取有效信息具 ...

最新文章

  1. histeq函数实现直方图的均衡化和规定化
  2. Oracle单实例打补丁
  3. 2020-12-14(全局/静态对象的构造函数和析构函数调用的时机以及地址)
  4. 前端 PDFObject.embed预览PDF,另类方式隐藏工具条样例
  5. [运动][组合]睡前运动
  6. Git初学札记(九)————EGit检出远程分支
  7. linux 下rpm软件的安装和卸载
  8. 实现视图示例_AngularJS控制器,范围和视图教程示例
  9. GJB150.5A-2009军用装备实验室温度冲击环境试验
  10. 怎么在Linux中安装gcc编译器使用,如何在linux中安装gcc编译器?
  11. 用云服务器搭建一个属于自己的网站(手把手教学)
  12. LOTO 示波器 两种电流探头的对比实测
  13. Windows XP更新后出现“你可能是盗版软件受害者”解决方法
  14. 漫画:用木兰从军说外观模式
  15. 超级经典的人生格言(搞笑)
  16. java的LocalDateTime类来获取当天时间、前一天时间,本周的开始和结束时间、本月的开始和结束时间
  17. MySQL5.7乱码问题
  18. 【面试题】Java 高级工程师面试刷题100题(二)
  19. FFmpeg源码分析:视频滤镜介绍(上)
  20. 蓝V企业号与个人号两者的区别,认证蓝V都有什么特权。

热门文章

  1. 怎么将JPG格式的图片转换成PDF文件?
  2. 纯离线本地的neovim翻译插件
  3. HTML中标签和元素的区别
  4. 新魔百和M304A-免费卡刷固件(当贝桌面,smartTV开机画面)
  5. UI设计师都能做什么,UI设计都有哪几个职业方向
  6. 博弈,游戏,是否有先手必胜的情况
  7. java camel,Camel企业级集成模式--Aggregator
  8. CheckStyle 编写自己的代码检查插件
  9. Unity ShaderLab 常用函数
  10. 一个公式三指标,电商分析的破局之道