How to use QBoat Sunny & QIoT Suite Lite to build Wi-Fi applications

299_1510208617_Qboat20Sunny_top-right202Bheat20sink

 Abstract

QBoat Sunny provides similar functions to a standard QNAP NAS, and provides outstanding performance for Edge Computing. In this tutorial, we will use Wi-Fi as an application scenario:

 

Diagram

photo 2

MediaTek LinkIt 7697 development board

 

Use HTTP to request the temperature and humidity readings from the DHT11.

 

Pin connections

 

DHT11 MediaTek LinkIt 7697
+ 5V
GND
DO P3

 

The code is as follows.

 

Please note that you can test the code by connecting a wireless AP router by LWiFi. If successful, then the DHT11 will send the temperature value via HTTP (for example: http://192.168.1.xxx/temp).

 

GET

Parameter

Function
/temp Acquire temperature value (Celsius)
/humi Acquire humidity value (Percentage)

 

<< MonitorNode.ino >>

 

#include <LWiFi.h>

#include “DHT.h”

#define DHTPIN 3 // what digital pin we’re connected to

#define WARNPIN 13

// Uncomment the type you are using

#define DHTTYPE DHT11 // DHT 11

//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

char ssid[] = “LaisanHere”; // your network SSID (name)

char pass[] = “t101419008”; // your network password

int keyIndex = 0; // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup() {

//Initialize serial and wait for the port to open:

Serial.begin(9600);

while (!Serial) {

; // wait for the serial port to connect. Needed for native USB port only

}

// attempt to connect to the Wi-Fi network:

while (status != WL_CONNECTED) {

Serial.print(“Attempting to connect to SSID: “);

Serial.println(ssid);

// Connect to a WPA/WPA2 network. Change this line if using an open or WEP network:

status = WiFi.begin(ssid, pass);

}

server.begin();

// you are now connected, so display the status:

printWifiStatus();

// Activate DHT11

dht.begin();

pinMode(WARNPIN, OUTPUT);

digitalWrite(WARNPIN, LOW);

}

void loop() {

// listen for incoming clients

WiFiClient client = server.available();

if (client) {

Serial.println(“new client”);

String msg;

String param;

// an HTTP request ends with a blank line

if (client.connected()) {

while (client.available()) {

char c = client.read();

msg += String(c);

}

}

Serial.print(msg);

int posi = msg.indexOf(“Referer: “);

if(posi > 0)

{

String sb = msg.substring(posi);

int p = sb.indexOf(“/”);

param = sb.substring(p+2);

p = param.indexOf(“/”);

param = param.substring(p, p+5);

}

else

{

posi = msg.indexOf(“GET”);

param = msg.substring(posi+4, posi+9);

}

Serial.println(param);

// send a standard HTTP response header

client.println(“HTTP/1.1 200 OK”);

client.println(“Content-Type: text/html”);

client.println(“Connection: close”); // the connection will be closed after completion of the response

client.println();

if(param == “/warn”)

{

digitalWrite(WARNPIN, HIGH);

client.println(“WARNING !!”);

}

if(param == “/cler”)

{

digitalWrite(WARNPIN, LOW);

client.println(“CLEAR”);

}

if(param == “/temp”)

{

float t = dht.readTemperature();

client.println(t);

}

if(param == “/humi”)

{

float h = dht.readHumidity();

client.println(h);

}

// close the connection:

client.stop();

Serial.println(“client disonnected”);

}

// give the web browser time to receive the data

delay(100);

}

void printWifiStatus() {

// display the SSID of the network you are connected to:

Serial.print(“SSID: “);

Serial.println(WiFi.SSID());

// display your Wi-Fi IP address:

IPAddress ip = WiFi.localIP();

Serial.print(“IP Address: “);

Serial.println(ip);

// display the received signal strength:

long rssi = WiFi.RSSI();

Serial.print(“signal strength (RSSI):”);

Serial.print(rssi);

Serial.println(” dBm”);

}

 

 

QBoat Sunny:

 

You can drag, drop and make the settings using the Node-RED broker in QIoT Suite Lite. You can use HTTP requests to receive the temperature and humidity status from the DHT11 every 0.5 and 1 minute respectively.

 

 

 

Related posts

Leave a Reply