WIZnet Developer Forum

Wizfi 250, IoT플랫폼 접속 에러 질문

얼마전에 위즈넷에서 위즈파이250 구매를 했고, 와서 테스트를 해봤는데요.

아두이노 메가+wizfi250 ==> ubidots.com 플랫폼 사이트 접속해서 센서값 관찰 및 LED 제어입니다.

센서는 잘 되는데, LED는 켜기 버튼을 누르면 접속이 중단되고 작동이 안되는데요.
안되는 모습을 영상으로 찍었습니다.아래에 URL로 가시면 볼수 있으십니다.

=> (유투브 영상) youtu.be/5AjYXcc6Zwo

꼭 좀 해결이 되었으면 합니다. 감사합니다.

//======== 아두이노 코드 ================//

#include <Arduino.h>
#include <SPI.h>
#include <IPAddress.h>
#include “WizFi250.h”
#include “WizFi250_tcp_client.h”

//Ubidots information
#define TOKEN “7pTbTJMMd0n0vpbDVxG3YGnGMNJiH5” //
#define VARID_LED_Red “5703ab65762542401b64cfe7” //

//Parse JSON
#define PARSE ““value””
#define ENDPARSE “,”

//Wi-Fi information
#define SSID “”
#define KEY “”//
#define AUTH “”

//Hardware Pin status
#define Pin_LED_Red 13

//Server information
char server[] = “thing.ubidots.com”;
//IPAddress server (50,23,124,68);
#define REMOTE_PORT 80

//Time to get the LED status
unsigned long lastGetTime = 0;
const unsigned long getInterval = 1 * 1000;

boolean Wifi_setup = false;
boolean lastConnected = false;

int SendMethod;

String rcvbuf;

WizFi250 wizfi250;
WizFi250_TCP_Client myClient(server, REMOTE_PORT);

// function
int postData(String VARID, float data);
int parser_value(String buf);
int getStatus(String VARID);
float getTempC();
char * floatToString(char * outstr, double val, byte precision, byte widthp);

//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here
Serial.begin(115200);
Serial.println("\r\nSerial Init");

pinMode(Pin_LED_Red, OUTPUT); //added
digitalWrite(Pin_LED_Red, LOW);

wizfi250.begin();
wizfi250.setDebugPrint(4);
wizfi250.hw_reset();

wizfi250.sync();
wizfi250.setDhcp();

for(int i = 0; i < 10; i++) // Try to join 30 times
{
if( wizfi250.join(SSID, KEY, AUTH) == RET_OK )
{
Wifi_setup = true;
break;
}
}
SendMethod = 0;
}

// The loop function is called in an endless loop
void loop()
{

if( Wifi_setup )
{
wizfi250.RcvPacket();

if( myClient.available() )
{
char c = myClient.recv();

if( c != NULL )
{
rcvbuf += c;
}
}
else
{
if(!myClient.getIsConnected() && lastConnected )
{
//Serial.println(rcvbuf);
int rcv_value = parser_value(rcvbuf, PARSE);
Serial.println(“disconnecting.”);
myClient.stop();

digitalWrite(Pin_LED_Red, rcv_value);
Serial.print("LED is ");

if(rcv_value)
Serial.println(“ON”);
else
Serial.println(“OFF”);

rcvbuf = “”;
}

if(!myClient.getIsConnected() && (millis() - lastGetTime > getInterval))
{
getStatus(VARID_LED_Red);
}

lastConnected = myClient.getIsConnected();
}
}
}

int getStatus(String VARID)
{

String TxData;

if(myClient.connect() == RET_OK)
{
Serial.println(“send GET”);

TxData = “GET /api/v1.6/variables/”;
TxData += VARID;
TxData += " HTTP/1.1\r\n";
TxData += “Host: things.ubidots.com\r\n”;
TxData += "X-Auth-Token: ";
TxData += TOKEN;
TxData += “\r\n”;
TxData += “Content-Type: application/json\r\n”;
TxData += “Connection: close\r\n”;
TxData += “\r\n\r\n”;

myClient.send((String)TxData);

lastGetTime = millis();

return true;
}

return false;
}

int parser_value(String buf, String Param)
{
int firstSign;
int secondSign;
int endSign;
String tmpVal;
int value;

firstSign = buf.indexOf(Param);
secondSign = buf.indexOf(’:’, firstSign);
endSign = buf.indexOf(ENDPARSE, secondSign);

tmpVal = buf.substring(secondSign + 1 , endSign);
tmpVal.trim();
value = tmpVal.toInt();

return value;

}

// =====================================//

안녕하세요

아래 소스코드에서 주석으로 되어있는 //Serial.println(rcvbuf);를 주석을 해제하고 테스트 해보시길 바랍니다.
//Serial.println(rcvbuf); => Serial.println(rcvbuf);

LED를 On/Off 하는 예제는, Ubidots에서 LED 프로젝트의 상태 데이터를 읽어와서(JSON format) 그 중 value 의 상태값을 읽는 예제입니다.
그래서 value가 1이면 on, 아니면 off 로 동작하게 됩니다.

올려주신 상황은 off일 경우에는 동작하게 되는데, 이 상황이 Off 즉 value가 0인 상태를 읽는 것이 확실한지 우선 체크해보아야 할 것 같습니다.

그래서 rcvbuf를 모두 출력하게 되면, WizFi250이 Ubidots와 정상적으로 상태값을 읽어오는 상황인지, 아니면 다른 문제 상황인지를 파악할 수 있을 것 같습니다.

=========================================================================

if(!myClient.getIsConnected() && lastConnected )
{
//Serial.println(rcvbuf);
int rcv_value = parser_value(rcvbuf, PARSE);
Serial.println(“disconnecting.”);
myClient.stop();

digitalWrite(Pin_LED_Red, rcv_value);
Serial.print("LED is ");

if(rcv_value)
Serial.println(“ON”);
else
Serial.println(“OFF”);

rcvbuf = “”;
}

rcvbuf안에 있는 rcv_value는 0 -> 1로 잘 변하고(웹에서 LED버튼 클릭시)
1로 변한것을 잘 받았다고 시리얼 모니터에 뿌려지는데요.
그래서 LED를 On한 다음에 다시 유비닷에 접속하는 부분에서 멈춰버립니다.
아래에 보시면은,


rcv_value = 1
disconnecting.
LED is ON

AT+FDNS=thing.ubidots.com,1000 // ==> 여기에서 멈춥니다. **************************************************

아래에는 와이파이 접속 부터 LED 온오프를 1번 클릭 할때까지의
상태값을 시리얼 모니터에 뿌린 겁니다.

//==============================================================================//

Serial Init

===== SPI Send =====
AT

==================

===== SPI Recv =====
WizFi250 Version 1.0.3.3 (WIZnet Co.Ltd)
AT
[OK]

==================

===== SPI Send =====
AT+MECHO=0

==================

===== SPI Recv =====
AT+MECHO=0
[OK]

==================

AT+WNET=1

[OK]

AT+WLEAVE

[OK]

AT+WSET=0,daddyslab_2_4G

[OK]

AT+WSEC=0,asdf7890

[OK]

AT+WJOIN

Joining : daddyslab_2_4G
Successfully joined : daddyslab_2_4G
[Link-Up Event]
IP Addr : 192.168.0.174
Gateway : 192.168.0.1
[OK]

AT+FDNS=thing.ubidots.com,1000

50.23.124.68
[OK]

AT+SCON=O,TCN,50.23.124.68,80,0

[OK]
[CONNECT 0]send GET

AT+SSEND=0,0.0.0.0,80,186

[0,186]
[OK]
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Apr 2016 01:29:11 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH

2d5
{“id”: “5703b88376254216c5afb846”, “name”: “led”, “icon”: “”, “unit”: “”, “datasource”: {“id”: “5703ab5b7625424037dd94bf”, “name”: “LED”, “url”: “http://things.ubidots.com/api/v1.6/datasources/5703ab5b7625424037dd94bf”}, “url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846”, “description”: “”, “properties”: {"_last_value": {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “_last_activity”: 1459992487000}, “tags”: [], “values_url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846/values”, “created_at”: “2016-04-05T13:07:15.314”, “last_value”: {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “last_activity”: 1459992487000, “type”: 0, “derived_expr”: “”}
0

rcv_value = 0
disconnecting.
LED is OFF

AT+FDNS=thing.ubidots.com,1000

50.23.124.68
[OK]

AT+SCON=O,TCN,50.23.124.68,80,0

[OK]
[CONNECT 0]send GET

AT+SSEND=0,0.0.0.0,80,186

[0,186]
[OK]
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Apr 2016 01:29:16 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH

2d5
{“id”: “5703b88376254216c5afb846”, “name”: “led”, “icon”: “”, “unit”: “”, “datasource”: {“id”: “5703ab5b7625424037dd94bf”, “name”: “LED”, “url”: “http://things.ubidots.com/api/v1.6/datasources/5703ab5b7625424037dd94bf”}, “url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846”, “description”: “”, “properties”: {"_last_value": {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “_last_activity”: 1459992487000}, “tags”: [], “values_url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846/values”, “created_at”: “2016-04-05T13:07:15.314”, “last_value”: {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “last_activity”: 1459992487000, “type”: 0, “derived_expr”: “”}
0

rcv_value = 0
disconnecting.
LED is OFF

AT+FDNS=thing.ubidots.com,1000

50.23.124.68
[OK]

AT+SCON=O,TCN,50.23.124.68,80,0

[OK]
[CONNECT 0]send GET

AT+SSEND=0,0.0.0.0,80,186

[0,186]
[OK]
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Apr 2016 01:29:21 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH

2d5
{“id”: “5703b88376254216c5afb846”, “name”: “led”, “icon”: “”, “unit”: “”, “datasource”: {“id”: “5703ab5b7625424037dd94bf”, “name”: “LED”, “url”: “http://things.ubidots.com/api/v1.6/datasources/5703ab5b7625424037dd94bf”}, “url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846”, “description”: “”, “properties”: {"_last_value": {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “_last_activity”: 1459992487000}, “tags”: [], “values_url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846/values”, “created_at”: “2016-04-05T13:07:15.314”, “last_value”: {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “last_activity”: 1459992487000, “type”: 0, “derived_expr”: “”}
0

rcv_value = 0
disconnecting.
LED is OFF

AT+FDNS=thing.ubidots.com,1000

50.23.124.68
[OK]

AT+SCON=O,TCN,50.23.124.68,80,0

[OK]
[CONNECT 0]send GET

AT+SSEND=0,0.0.0.0,80,186

[0,186]
[OK]
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Apr 2016 01:29:27 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH

2d5
{“id”: “5703b88376254216c5afb846”, “name”: “led”, “icon”: “”, “unit”: “”, “datasource”: {“id”: “5703ab5b7625424037dd94bf”, “name”: “LED”, “url”: “http://things.ubidots.com/api/v1.6/datasources/5703ab5b7625424037dd94bf”}, “url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846”, “description”: “”, “properties”: {"_last_value": {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “_last_activity”: 1459992487000}, “tags”: [], “values_url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846/values”, “created_at”: “2016-04-05T13:07:15.314”, “last_value”: {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “last_activity”: 1459992487000, “type”: 0, “derived_expr”: “”}
0

rcv_value = 0
disconnecting.
LED is OFF

AT+FDNS=thing.ubidots.com,1000

50.23.124.68
[OK]

AT+SCON=O,TCN,50.23.124.68,80,0

[OK]
[CONNECT 0]send GET

AT+SSEND=0,0.0.0.0,80,186

[0,186]
[OK]
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Apr 2016 01:29:32 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH

2d5
{“id”: “5703b88376254216c5afb846”, “name”: “led”, “icon”: “”, “unit”: “”, “datasource”: {“id”: “5703ab5b7625424037dd94bf”, “name”: “LED”, “url”: “http://things.ubidots.com/api/v1.6/datasources/5703ab5b7625424037dd94bf”}, “url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846”, “description”: “”, “properties”: {"_last_value": {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “_last_activity”: 1459992487000}, “tags”: [], “values_url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846/values”, “created_at”: “2016-04-05T13:07:15.314”, “last_value”: {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “last_activity”: 1459992487000, “type”: 0, “derived_expr”: “”}
0

rcv_value = 0
disconnecting.
LED is OFF

AT+FDNS=thing.ubidots.com,1000

50.23.124.68
[OK]

AT+SCON=O,TCN,50.23.124.68,80,0

[OK]
[CONNECT 0]send GET

AT+SSEND=0,0.0.0.0,80,186

[0,186]
[OK]
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Apr 2016 01:29:37 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH

2d5
{“id”: “5703b88376254216c5afb846”, “name”: “led”, “icon”: “”, “unit”: “”, “datasource”: {“id”: “5703ab5b7625424037dd94bf”, “name”: “LED”, “url”: “http://things.ubidots.com/api/v1.6/datasources/5703ab5b7625424037dd94bf”}, “url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846”, “description”: “”, “properties”: {"_last_value": {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “_last_activity”: 1459992487000}, “tags”: [], “values_url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846/values”, “created_at”: “2016-04-05T13:07:15.314”, “last_value”: {“timestamp”: 1459992487529, “value”: 0.0, “context”: {}}, “last_activity”: 1459992487000, “type”: 0, “derived_expr”: “”}
0

rcv_value = 0
disconnecting.
LED is OFF

AT+FDNS=thing.ubidots.com,1000

50.23.124.68
[OK]

AT+SCON=O,TCN,50.23.124.68,80,0

[OK]
[CONNECT 0]send GET

AT+SSEND=0,0.0.0.0,80,186

[0,186]
[OK]
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Apr 2016 01:29:43 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: GET, PUT, DELETE, HEAD, OPTIONS, PATCH

2d5
{“id”: “5703b88376254216c5afb846”, “name”: “led”, “icon”: “”, “unit”: “”, “datasource”: {“id”: “5703ab5b7625424037dd94bf”, “name”: “LED”, “url”: “http://things.ubidots.com/api/v1.6/datasources/5703ab5b7625424037dd94bf”}, “url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846”, “description”: “”, “properties”: {"_last_value": {“timestamp”: 1459992579286, “value”: 1.0, “context”: {}}, “_last_activity”: 1459992579000}, “tags”: [], “values_url”: “http://things.ubidots.com/api/v1.6/variables/5703b88376254216c5afb846/values”, “created_at”: “2016-04-05T13:07:15.314”, “last_value”: {“timestamp”: 1459992579286, “value”: 1.0, “context”: {}}, “last_activity”: 1459992579000, “type”: 0, “derived_expr”: “”}
0

rcv_value = 1
disconnecting.
LED is ON

AT+FDNS=thing.ubidots.com,1000

//================================================================================//

** 아 그리고, 참고사항이 있는데요.

아두이노 우노 + 아두이노 정품 와이파이쉴드(아두이노에서 만든것)를 결합해서
똑같은 인터넷 네트워크하에, 위에서 했던 유비닷 LED제어를 하면 작동이 잘 됩니다.

하지만 wizfi250만 현재 이 문제가 있어서요…

이 문제는 Pin_LED_Red 핀이 13으로 define 되어 있는데,
13번 핀은 아두이노와 WizFi250의 SPI 통신으로 사용되는 핀 중 하나입니다.

따라서 LED가 켜지면서 13번 핀을 강제로 high로 만들었기 때문에 SPI 통신이 되지 않는 문제입니다.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.