Connecting a Sensor to a Local Network

Here is a use case on connecting a Simple Sensor/Smart IoT product to a local network and send data and receive commands.

IoT Product Examples
Smart White Goods
Water Heater, Washer/Dryer, Water Softener
Home Automation
Thermostat, Smart Plug, Lighting Control
Home Medical
Patient Monitoring, Elder Care, Baby Monitoring
Kitchen of Things
Coffee Maker, Microwave, Crockpot

UseCase # 1

AT Command Example in C using WPS ( Wi-Fi Protected Setup or Pushbutton)

if (USERCASE == 1) {
printf(“Use Case 1 selected”);

// Set up WLAN
Send_AT_Command(“CW=3\r\n); // start wps exchange with Access Point
while (!read_from_console(Wait_for_connection_to_AP)); // look for AP connection message

// Set up TCP Server
Send_AT_Command(“P0=0\r\n”); // set TCP Communication bank to bank zero
Send_AT_Command(“P1=0\r\n”); // set Communication mode to TCP
Send_AT_Command(“P2=8003\r\n”); // set TCP Port number
Send_AT_Command(“S1=15\r\n”); // set TCP send buffer to 15 bytes
Send_AT_Command(“R1=15\r\n”); // set TCP receive buffer to 15 bytes
Send_AT_Command(“P5=1\r\n”); // START UP TCP server
while (!read_from_console(Wait_for_connected_client)); // wait for client to connect to

// tcp server
Send_AT_Command(“S0\r\nHello World!\r\n”); // send message to client
Send_AT_Command(“R0”); // request available (n bytes) data
// from TCP stack
printf(“%S\n\r”, read_from_console(tcp_message)); // print message received from client. Eg.
// Response: “You Exist!”
Send_AT_Command(“P5=0\r\n”); // Shutdown TCP Server
Send_AT_Command(“CD\r\n”); // Close Network Connect to Access Point
}

Here is the project in Python

if (USECASE == 1):
print “Use Case 1 selected”

#WLAN
useSoftAP = 3 #Join using, 0 = Cx commands, 1 = A0 (SoftAP),
# 2 = AD Direct Mode (SoftAP), 3 – WPS PBC
#Communication
SOCKET = “0” #Select Socket 0-3
PROTOCOL=”0″ #TCP=0, UDP=1, UDP-Lite=2 TCP-SSL=3
client_server = 1 #Client=0, Server=1
localPort = “8003” #Local server port
#Mode
writeRead = 2 #0=Write Only, 1=Read Only, 2=Write/Read(1:1),
# 3 = Local Echo(Read/Write)
#End if

2015-07-02T18:54:08+00:00 2018-06-06T23:58:27+00:00