test
Dependencies: MTS-Serial libmDot mbed-rtos mbed
Fork of mDot_LoRa_Connect_Example by
Diff: lora-task.cpp
- Revision:
- 6:f87d57498fd0
- Parent:
- 5:f16b067257b6
--- a/lora-task.cpp Fri Oct 13 10:30:14 2017 +0000 +++ b/lora-task.cpp Wed Nov 08 12:10:51 2017 +0000 @@ -18,8 +18,8 @@ extern int ble_flag; extern int zigbee_flag; char gateway_buffer[128]; -int device_buffer[8]; - +int device_buffer[16]; +int temp =0; int process_gateway_data(const char *device_type, int *device_buffer, char *data_buffer) { const char *pBuf; @@ -37,9 +37,10 @@ return false; } - pBuf += 13; - - len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + pBuf += 12; + //pBuf += 11; + //len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + len = strstr((const char *)pBuf, ",") - (char *)pBuf; /* ends with / */ if (len <= 0) { my_mutex.unlock(); return false; @@ -47,8 +48,9 @@ strncpy ((char *)device_type, (const char *)pBuf, len); printf("device type is %s\r\n", device_type); if (!strcmp(device_type, "ble_bulbs")) { - device_buffer[0] = 0xB3; - device_buffer[1] = 0x01; + device_buffer[0] = 0x04; + device_buffer[1] = 0xCE; + device_buffer[2] = 0x01; pBuf = strstr((const char *)pBuf, "powered"); if (!pBuf) { @@ -56,7 +58,7 @@ my_mutex.unlock(); return false; } - + pBuf += 9; len = strstr((const char *)pBuf, ",") - (char *)pBuf; /* ends with / */ if (len <= 0) { @@ -65,13 +67,13 @@ } if (!strncmp ((char *)pBuf, "true", len)) { - device_buffer[2] = 0x01; + device_buffer[3] = 0x01; } else if (!strncmp ((char *)pBuf, "false", len)) { - device_buffer[2] = 0x00; + device_buffer[3] = 0x00; } else { - device_buffer[2] = 0x02; + device_buffer[3] = 0x02; } pBuf = strstr((const char *)pBuf, "color"); @@ -81,33 +83,34 @@ return false; } - pBuf += 8; - len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + pBuf += 7; + //len = strstr((const char *)pBuf, ",") - (char *)pBuf - 1; /* ends with / */ + len = strstr((const char *)pBuf, ",") - (char *)pBuf; /* ends with / */ if (len <= 0) { my_mutex.unlock(); return false; } if (!strncmp ((char *)pBuf, "red", len)) { - device_buffer[3] = 0x00; + device_buffer[4] = 0x00; } else if (!strncmp ((char *)pBuf, "green", len)) { - device_buffer[3] = 0x01; + device_buffer[4] = 0x01; } else if (!strncmp ((char *)pBuf, "blue", len)){ - device_buffer[3] = 0x02; + device_buffer[4] = 0x02; } else if (!strncmp ((char *)pBuf, "yellow", len)){ - device_buffer[3] = 0x03; + device_buffer[4] = 0x03; } else if (!strncmp ((char *)pBuf, "cyan", len)){ - device_buffer[3] = 0x04; + device_buffer[4] = 0x04; } else if (!strncmp ((char *)pBuf, "magenta", len)){ - device_buffer[3] = 0x05; + device_buffer[4] = 0x05; } else { - device_buffer[3] = 0x06; + device_buffer[4] = 0x06; } pBuf = strstr((const char *)pBuf, "dim"); if (!pBuf) { @@ -117,7 +120,7 @@ } pBuf += 5; - device_buffer[4] = atoi(pBuf); + device_buffer[5] = atoi(pBuf); my_mutex.unlock(); return true; } @@ -218,13 +221,37 @@ osDelay(1000); //continue; } - //strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":true,\"color\":\"red\",\"dim\":50}}"); + /* + if(temp == 0) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":false,\"color\":\"red\",\"dim\":50}}"); + temp++; + } + else if(temp == 1) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":true,\"color\":\"red\",\"dim\":50}}"); + temp++; + } + else if(temp == 2) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":any,\"color\":\"red\",\"dim\":50}}"); + temp++; + } + else if(temp == 3) + { + strcpy(gateway_buffer, "{\"DeviceType\":\"ble_bulbs\",\"DeviceName\":\"bulb1\",\"DeviceCommand\":\"desired_state\": {\"powered\":any,\"color\":\"green\",\"dim\":50}}"); + temp++; + } + else if(temp ==4) + { + temp =0; + }*/ printf("data received in mdot from gateway: %s\r\n", gateway_buffer); memset(device_type, 0, 16); res = process_gateway_data(device_type, device_buffer, gateway_buffer); if (res == true) { - printf("device_buffer data is: %X, %X, %X, %X, %d\r\n", device_buffer[0], device_buffer[1], device_buffer[2], device_buffer[3], device_buffer[4]); + printf("device_buffer data is: %X, %X, %X, %X, %d %d\r\n", device_buffer[0], device_buffer[1], device_buffer[2], device_buffer[3], device_buffer[4], device_buffer[5]); if (strcmp(device_type, "ble_bulbs") == 0) { printf("sending data to BLE\r\n");