Skip to content

Commit

Permalink
Merge branch 'hotfix/#19'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky-Kwon committed May 1, 2018
2 parents db7c2fc + f18119d commit 066adc4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 33 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ Install JAVA Runtime Environment

## Revision History

### v1.2.1

- Fixed bugs
- Fixed a bug that stops when the module switches to data mode and at-command mode.
- The MQTT socket has been modified to open as a nonblock.
- Modified the memory used for MQTT publishing from static to dynamic allocation.
- Fixed to update connection LED and network state when switching to at-command mode.

### v1.2.0

- Added features
Expand Down
1 change: 0 additions & 1 deletion WIZ550S2E_App/src/Configuration/ConfigData.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#define NAME_LEN 25

#define MQTT_ACCOUNT_LEN 10
#define MQTT_PASS_LEN 10
#define MQTT_TOPIC_LEN 25

enum baud {
Expand Down
3 changes: 2 additions & 1 deletion WIZ550S2E_App/src/Internet/MQTT/mqtt_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include "mqtt_interface.h"
#include "wizchip_conf.h"
#include "socket.h"

unsigned long MilliTimer;

Expand Down Expand Up @@ -160,7 +161,7 @@ int InitNetwork(Network* n)
{
int ret = 0;

ret = socket(n->my_socket, Sn_MR_TCP, 0, 0x00);
ret = socket(n->my_socket, Sn_MR_TCP, 0, SF_IO_NONBLOCK);

return ret;
}
Expand Down
70 changes: 48 additions & 22 deletions WIZ550S2E_App/src/S2E/S2E.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,36 @@ uint32_t uart_recv_cnt = 0;
uint32_t ether_send_cnt = 0;
uint32_t ether_recv_cnt = 0;

extern Network mqttNetwork;
extern MQTTClient mqttClient;
extern MQTTPacket_connectData mqttConnectData;
unsigned char mqtt_buf[WORK_BUF_SIZE] = {'\0',};
Network mqttNetwork;
MQTTClient mqttClient;

static uint8_t mqttInit = 0;

static void messageArrived(MessageData* md)
{
uint16_t len = 0;
uint16_t subMessagelen = 0;
int subTopiclen = 0;
MQTTMessage* mqttSubMessage = md->message;
MQTTString* mqttSubTopic = md->topicName;

subMessagelen = (int)mqttSubMessage->payloadlen;
subTopiclen = mqttSubTopic->lenstring.len;

len = (int)mqttSubMessage->payloadlen;
#ifdef __MQTT_DEBUG__
printf("messageArrived : %s, %d\r\n", (char*)mqttSubTopic->lenstring.data, subTopiclen);
#endif

if(len > UART_SRB_SIZE)
len = UART_SRB_SIZE;
if(subMessagelen > UART_SRB_SIZE)
subMessagelen = UART_SRB_SIZE;

if((len > 0) && len <= RingBuffer_GetFree(&txring))
ether_recv_cnt += len;
if((subMessagelen > 0) && subMessagelen <= RingBuffer_GetFree(&txring))
ether_recv_cnt += subMessagelen;
else
len = 0;
subMessagelen = 0;

if(len) {
if(subMessagelen) {
Chip_UART_SendRB(LPC_USART, &txring, (char*)mqttSubMessage->payload, (int)mqttSubMessage->payloadlen);
uart_send_cnt += len;
uart_send_cnt += subMessagelen;
}
}

Expand Down Expand Up @@ -203,6 +210,8 @@ static void uart_to_ether(uint8_t sock)
uint16_t len = 0;
int ret, uart_read_len = sizeof(g_send_buf);

char *mqtt_buf_ptr;

if(RingBuffer_IsEmpty(&rxring))
return;

Expand Down Expand Up @@ -260,8 +269,16 @@ static void uart_to_ether(uint8_t sock)

/* Data Transfer */
if(net->working_mode == MQTT) {
memset(mqtt_buf, '\0', sizeof(mqtt_buf));
len = Chip_UART_ReadRB(LPC_USART, &rxring, &mqtt_buf, uart_read_len);
mqtt_buf_ptr = (char *)malloc(sizeof(char)*uart_read_len);

if(mqtt_buf_ptr == NULL) {
#ifdef __MQTT_DEBUG__
printf("MQTT Out of memory for publish\r\n");
#endif
return;
}

len = Chip_UART_ReadRB(LPC_USART, &rxring, mqtt_buf_ptr, uart_read_len);
}
else
len = Chip_UART_ReadRB(LPC_USART, &rxring, &g_send_buf, uart_read_len);
Expand All @@ -287,12 +304,13 @@ static void uart_to_ether(uint8_t sock)
else if(sock_state == SOCK_ESTABLISHED)
{
if(net->working_mode == MQTT) {
mqttPubMessage.payload = mqtt_buf;
mqttPubMessage.payload = mqtt_buf_ptr;
mqttPubMessage.payloadlen = len;
mqttPubMessage.qos = QOS0;
mqttPubMessage.retained = 0;
mqttPubMessage.dup = 0;
ret = MQTTPublish(&mqttClient, option->mqtt_publish_topic, &mqttPubMessage);
free(mqtt_buf_ptr);
if(ret != SUCCESSS) {
#ifdef __MQTT_DEBUG__
printf("MQTT publish error - ret : %d\r\n", ret);
Expand Down Expand Up @@ -466,6 +484,10 @@ static void trigger_state3_process(uint8_t sock)
Chip_UART_SendRB(LPC_USART, &txring, "[S,0]\r\n", 7);
op_mode = OP_COMMAND;

Board_LED_Set(1, false);

net->state = net_disconnect;

close(sock);
return;
}
Expand Down Expand Up @@ -493,6 +515,11 @@ static void s2e_sockclose_process(uint8_t sock)

switch(net->working_mode) {
case MQTT:
if(mqttInit == 0) {
mqttInit = 1;
NewNetwork(&mqttNetwork, sock);
}
MQTTClientInit(&mqttClient, &mqttNetwork, 1000, g_send_buf, WORK_BUF_SIZE, g_recv_buf, WORK_BUF_SIZE);
InitNetwork(&mqttNetwork);
break;
case TCP_CLIENT_MODE:
Expand Down Expand Up @@ -597,6 +624,8 @@ static void s2e_sockestablished_process(uint8_t sock)
int ret;
S2E_Packet *value = get_S2E_Packet_pointer();

MQTTPacket_connectData mqttConnectData = MQTTPacket_connectData_initializer;

if(reconn_flag)
reconn_flag = reconn_time = 0;

Expand All @@ -608,8 +637,8 @@ static void s2e_sockestablished_process(uint8_t sock)
return;
}
case MQTT:
if(getSn_IR(SOCK_MQTT) & Sn_IR_CON) {
setSn_IR(SOCK_MQTT,Sn_IR_CON);
if(getSn_IR(sock) & Sn_IR_CON) {
setSn_IR(sock,Sn_IR_CON);

mqttConnectData.MQTTVersion = 4;
mqttConnectData.clientID.cstring = value->module_name;
Expand All @@ -626,7 +655,7 @@ static void s2e_sockestablished_process(uint8_t sock)
#endif
}

ret = MQTTSubscribe(&mqttClient, value->options.mqtt_subscribe_topic, QOS0, messageArrived);
ret = MQTTSubscribe(&mqttClient, value->options.mqtt_subscribe_topic, QOS0, (volatile)messageArrived);
if(ret != SUCCESSS) {
#ifdef __MQTT_DEBUG__
printf("MQTT subscribe error - ret : %d\r\n", ret);
Expand Down Expand Up @@ -758,9 +787,6 @@ void s2e_run(uint8_t sock)
struct __options *option = (struct __options *)&(get_S2E_Packet_pointer()->options);
uint8_t sock_state;

if(net->working_mode == MQTT)
sock = SOCK_MQTT;

getsockopt(sock, SO_STATUS, &sock_state);

#ifdef __TRIG_DEBUG__
Expand Down
3 changes: 1 addition & 2 deletions WIZ550S2E_App/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

#define MAJOR_VER 1
#define MINOR_VER 2
#define MAINTENANCE_VER 0
#define MAINTENANCE_VER 1

#define SOCK_DATA 0
#define SOCK_CONFIG 1
#define SOCK_TFTP 2
#define SOCK_DHCP 3
#define SOCK_DNS 4
#define SOCK_MQTT 5

#define OP_COMMAND 0
#define OP_DATA 1
Expand Down
7 changes: 0 additions & 7 deletions WIZ550S2E_App/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ uint8_t g_recv_buf[WORK_BUF_SIZE] = {'\0',};

uint8_t run_dns = 1;
uint8_t op_mode;

Network mqttNetwork;
MQTTClient mqttClient;
MQTTPacket_connectData mqttConnectData = MQTTPacket_connectData_initializer;
/*****************************************************************************
* Private functions
****************************************************************************/
Expand Down Expand Up @@ -147,9 +143,6 @@ int main(void)
}
}

NewNetwork(&mqttNetwork, SOCK_MQTT);
MQTTClientInit(&mqttClient, &mqttNetwork, 1000, g_send_buf, WORK_BUF_SIZE, g_recv_buf, WORK_BUF_SIZE);

atc_init();

op_mode = OP_DATA;
Expand Down

0 comments on commit 066adc4

Please sign in to comment.