https://kocoafab.cc/tutorial/view/656
위 글을 보고 그대로 따라하고 있는데
뭘 어떻게 바꿔도 LED Value가 0에서 바뀌질 않습니다
//
Serial Init
[WizFi250] Initializing WizFi250
Attempting to connect to WPA SSID: ****
[WizFi250] Connected to ****
You're connected to the network
SSID: ****
IP Address: 192.168.*.***
Signal strength (RSSI):-39 dBm
[WizFi250] Connecting to thing.ubidots.com
Connecting...
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Mon, 24 Jul 2017 13:25:33 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept, Cookie
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
29c
{"id":"597551fac03f972f68e27367","name":"LED Value","icon":"cloud-upload","unit":null,"label":"led-control","datasource":{"id":"596f06a3c03f9727c66b1b5c","name":"LED Control","url":"http://things.ubidots.com/api/v1.6/datasources/596f06a3c03f9727c66b1b5c"},"url":"http://things.ubidots.com/api/v1.6/variables/597551fac03f972f68e27367","description":null,"properties":{},"tags":[],"created_at":"2017-07-24T01:48:42.403000","last_value":{"timestamp":1500902715805,"context":{},"value":1.0,"id":"5975f53bc03f976e6288f65b"},"last_activity":1500902715000,"type":0,"derived_expr":"","values_url":"http://things.ubidots.com/api/v1.6/variables/597551fac03f972f68e27367/values"}
0
[DISCONNECT 0]
�value : 0
LED is OFF
//
초기는 당연히 이렇게 떠야하지만 ubidots 사이트에서 led value를 계속 바꿔줘도 여전히
value : 0
LED is OFF
로만 뜨네요... 뭐가 잘못된건지 알려주세요ㅠㅠㅠ
소스코드 첨부합니다
==========================================================
#include
#include "WizFi250.h"
int getInt(String input);
//Ubidots information
#define TOKEN "A1E-SJn4jE8yMZloL5JullKKlnjeJHKPHC"
#define VARID "597551fac03f972f68e27367"
//Parse JSON
#define PARSE "\"value\""
#define ENDPARSE ","
char ssid[] = "haan"; // your network SSID (name)
char pass[] = "haanhaan1"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
//Hardware Pin status
#define Pin_LED_Red 8
char server[] = "thing.ubidots.com";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 1000L; // delay between updates, in milliseconds
boolean readingVal;
boolean getIsConnected = false;
String valString;
int val, temp;
String rcvbuf;
// Initialize the Ethernet client object
WiFiClient client;
void httpRequest();
void printWifiStatus();
void setup()
{
// initialize serial for debugging
Serial.begin(115200);
Serial.println(F("\r\nSerial Init"));
pinMode(Pin_LED_Red, OUTPUT); //added
digitalWrite(Pin_LED_Red, LOW);
WiFi.init();
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
printWifiStatus();
}
void loop() {
// if there's incoming data from the net connection send it out the serial port
// this is for debugging purposes only
while (client.available()) {
char c = client.read();
if ( c != NULL ) {
if (rcvbuf.length() > 20)
rcvbuf = "";
rcvbuf += c;
Serial.write(c);
}
if ( rcvbuf.endsWith("\"value\": ")) {
readingVal = true;
valString = "";
}
if (readingVal) {
if (c != '.') {
valString += c;
}
else {
readingVal = false;
}
}
}
// if 10 seconds have passed since your last connection,
// then connect again and send data
if (millis() - lastConnectionTime > postingInterval) {
if (getIsConnected) {
Serial.print(F("value : "));
val = getInt(valString);
Serial.println(val);
Serial.print(F("LED is "));
//Serial.println(rcv_value);
if (val) {
Serial.println(F("ON"));
digitalWrite(Pin_LED_Red, HIGH);
}
else {
Serial.println(F("OFF"));
digitalWrite(Pin_LED_Red, LOW);
}
}
httpRequest();
}
rcvbuf = "";
}
// this method makes a HTTP connection to the server
void httpRequest() {
Serial.println();
// close any connection before send a new request
// this will free the socket on the WiFi shield
client.stop();
// if there's a successful connection
if (client.connect(server, 80)) {
Serial.println("Connecting...");
// send the HTTP PUT request
client.print("GET /api/v1.6/variables/");
client.print(VARID);
client.println(" HTTP/1.1");
client.println("Host: things.ubidots.com");
client.print("X-Auth-Token: ");
client.println(TOKEN);
client.println("Content-Type: application/json");
client.println("Connection: close\r\n");
// note the time that the connection was made
lastConnectionTime = millis();
getIsConnected = true;
}
else {
// if you couldn't make a connection
Serial.println("Connection failed");
getIsConnected = false;
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
int getInt(String input) {
char carray[20];
//Serial.println(input);
input.toCharArray(carray, sizeof(carray));
//Serial.println(carray);
temp = atoi(carray);
return temp;
}
==========================================================
ubidots 값 변화 입니다.
|