APUE course source code
2a5d865c945698903fb4986729d574bac98827d1..dde12e90020d6a426ab12c8c1e9dba22f14bcc7e
2 days ago guowenxue
Update mqttd project for new JSON string
dde12e diff | tree
2 days ago guowenxue
update udp server example code
175027 diff | tree
3 files modified
28 ■■■■■ changed files
ch2.socket/udps.c 2 ●●● patch | view | raw | blame | history
project/4.mqttd/etc/iotd.conf 16 ●●●● patch | view | raw | blame | history
project/4.mqttd/iotd.c 10 ●●●● patch | view | raw | blame | history
ch2.socket/udps.c
@@ -71,7 +71,7 @@
        /* send message to socket client */
        printf("Reply back to socket client...\n");
        snprintf(buf, sizeof(buf), "Hello, socket client [%s:%d]\n", inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));
        if( (rv=sendto(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&cli_addr, addr_len)) < 0)
        if( (rv=sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&cli_addr, addr_len)) < 0)
        {
            printf("Reply back to socket client[%d] failure: %s\n", sockfd, strerror(errno));
            break;
project/4.mqttd/etc/iotd.conf
@@ -8,20 +8,20 @@
rgbled=1
# 是否使能继电器模块,0:禁用 1:使能
relay=0
relay=1
# 是否使能 DS18b20 温度传感器模块,0:禁用  1:使能
ds18b20=0
ds18b20=1
# 是否使能 SHT2X 温湿度传感器模块,0:禁用  1:使能
sht2x=1
sht2x=0
[logger]
# 日志记录文件
file=/var/log/iotd.log
# 日志级别: 0:ERROR 1:WARN 2:INFO 3:DEBUG 4:TRACE
# 日志级别: 0:ERROR 1:WARN 2:INFO 3:DEBUG 4:TRACE
level=2
# 日志回滚大小
@@ -56,10 +56,10 @@
[subsciber]
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "RedLed":"on" }'
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "GreenLed":"on" }'
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "BlueLed":"on" }'
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "Relay":"on" }'
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "RedLed":1 }'
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "GreenLed":1 }'
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "BlueLed":1 }'
# mosquitto_pub -h weike-iot.com -p 8013 -u lingyun -P lingyun -t \$Sys/Studio/Downlink/rpi001 -m '{ "Relay":1 }'
subTopic="$Sys/Studio/Downlink"
subQos=0
project/4.mqttd/iotd.c
@@ -230,10 +230,7 @@
            if( !item )
                continue;
            if( !strcasecmp(item->valuestring, "on") )
                turn_relay(which, ON);
            else if( !strcasecmp(item->valuestring, "off") )
                turn_relay(which, OFF);
            turn_relay(which, item->valueint);
        }
    }
@@ -246,10 +243,7 @@
            if( !item )
                continue;
            if( !strcasecmp(item->valuestring, "on") )
                turn_led(which, ON);
            else if( !strcasecmp(item->valuestring, "off") )
                turn_led(which, OFF);
            turn_led(which, item->valueint);
        }
    }