marcoschwartz / aREST_UI

Embedded UI for the aREST framework
72 stars 34 forks source link

Does not compile on ESP8266 #1

Closed probonopd closed 8 years ago

probonopd commented 9 years ago

Cannot compile on ESP8266

/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h: In member function 'virtual void aREST_UI::root_answer()':
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:71:69: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
                                                                     ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:72:31: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<html><head>");
                               ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:73:91: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
                                                                                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:74:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<script ");
                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:75:70: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("src=\"http://code.jquery.com/jquery-2.1.3.min.js\">");
                                                                      ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:76:28: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("</script>");
                            ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:77:118: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<script type='text/javascript' src='http://cdn.rawgit.com/Foliotek/AjaxQ/master/ajaxq.js'></script>");
                                                                                                                      ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:78:112: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<style>.row {margin-top: 30px;} .indicator {font-size: 30px; vertical-align: middle;}</style>");
                                                                                                                ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:79:123: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css\">");
                                                                                                                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:80:32: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("</head><body>");
                                ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:81:44: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<div class=\"container\">");
                                            ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:85:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<h1>");
                         ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:86:27: error: no matching function for call to 'aREST_UI::addToBuffer(String&)'
       addToBuffer(ui_title);
                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:86:27: note: candidates are:
In file included from ESP8266.ino:10:0:
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:832:6: note: void aREST::addToBuffer(char*)
 void addToBuffer(char * toAdd){
      ^
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:832:6: note:   no known conversion for argument 1 from 'String' to 'char*'
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:846:6: note: void aREST::addToBuffer(uint16_t)
 void addToBuffer(uint16_t toAdd){
      ^
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:846:6: note:   no known conversion for argument 1 from 'String' to 'uint16_t {aka short unsigned int}'
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:855:6: note: void aREST::addToBuffer(int)
 void addToBuffer(int toAdd){
      ^
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:855:6: note:   no known conversion for argument 1 from 'String' to 'int'
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:875:6: note: void aREST::addToBuffer(const __FlashStringHelper*)
 void addToBuffer(const __FlashStringHelper *toAdd){
      ^
/Users/user/Documents/Arduino/libraries/aREST/aREST.h:875:6: note:   no known conversion for argument 1 from 'String' to 'const __FlashStringHelper*'
In file included from ESP8266.ino:11:0:
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:87:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("</h1>");
                          ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:90:39: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<h1>Interface</h1>");
                                       ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:95:40: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class=\"row\">");
                                        ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:96:106: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class=\"col-md-2\"><button class=\"btn btn-block btn-lg btn-primary\" id='btn_on");
                                                                                                          ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:98:40: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("'>On</button></div>");
                                        ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:99:106: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class=\"col-md-2\"><button class=\"btn btn-block btn-lg btn-danger\" id='btn_off");
                                                                                                          ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:101:41: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("'>Off</button></div>");
                                         ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:102:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("</div>");
                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:107:40: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class=\"row\">");
                                        ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:108:112: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class=\"col-md-2\"><input type='range' value='0' max='255' min='0' step='5' id='slider");
                                                                                                                ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:110:29: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("'></div>");
                             ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:111:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("</div>");
                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:116:40: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class=\"row\">");
                                        ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:117:53: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class='col-md-3 indicator'>");
                                                     ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:119:29: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer(": </div>");
                             ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:120:57: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("<div class='col-md-3 indicator' id='");
                                                         ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:122:29: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("'></div>");
                             ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:123:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("</div>");
                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:126:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("</div>");
                         ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:128:59: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("<script>$( document ).ready(function() {");
                                                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:132:31: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("$('#btn_on");
                               ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:134:67: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("').click(function() {$.getq('queue','/digital/");
                                                                   ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:136:29: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("/1');});");
                             ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:137:32: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("$('#btn_off");
                                ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:139:67: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("').click(function() {$.getq('queue','/digital/");
                                                                   ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:141:29: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("/0');});");    
                             ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:146:31: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("$('#slider");
                               ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:148:64: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("').mouseup(function() {var val = $('#slider");
                                                                ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:150:55: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("').val(); $.getq('queue','/analog/");
                                                       ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:152:35: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("/' + val); });");      
                                   ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:157:38: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("$.getq('queue','/");
                                      ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:159:45: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("', function(data) { $('#");
                                             ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:161:34: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("').html(data.");
                                  ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:163:27: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
       addToBuffer("); });"); 
                           ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:166:31: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("});</script>");
                               ^
/Users/user/Documents/Arduino/libraries/aREST_UI-master/aREST_UI.h:168:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
     addToBuffer("</body></html>\r\n");
                                     ^
ESP8266.ino: In function 'void setup()':
ESP8266.ino:41:43: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
ESP8266.ino:44:33: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
ESP8266.ino:47:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
ESP8266.ino:48:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
Error compiling.

I am using the latest http://github.com/esp8266/Arduino from git.

marcoschwartz commented 9 years ago

Hello @probonopd , please refer to the latest install instructions on:

https://github.com/marcoschwartz/aREST

You basically have to use the board manager of the Arduino IDE to get the ESP8266 package. Let me know if this works!

probonopd commented 9 years ago

I managed to get it to run but it is confusing that there are different versions of the code using the same version number.

marcoschwartz commented 9 years ago

You mean because aREST UI has a different version number compared to aREST ?

probonopd commented 9 years ago

No, i mean https://www.diffchecker.com/tdo0jkvt - left hand: from the Releases page, right hand: from the GIT repo. Both mention the same version number. One of the two ended up working for me but i forgot which one.

marcoschwartz commented 8 years ago

Closing this, I'll be careful about version numbers in the future :)

zetalif commented 8 years ago

Hi Marco,

I've the same problem using Arduino IDE 1.6.5 and using board manager to get ESP8266 package. Also I've tried to reinstall all but the problem still remains. May you help me?

thank you in advance

regards

marcoschwartz commented 8 years ago

Hi Zetalif, can you give me details about the error? Thanks!

zetalif commented 8 years ago

Hi Marco, First of all thank you very much for your libraries and your tutorials. I've exactly the same errors reported by /probonopd. In any case after some trials, also with these errors, I was able to work with the sketch. Now the only problem is that connecting with my smartphone I can drive the led/relay only for few times after that it seems esp8266 (I've the esp01 version by bangood) lost the communication. May you give me some suggestion/ help to solve this? Thank you in advance Zetalif

zetalif commented 8 years ago

Hi Marco, I'm trying to send variables values to ThingSpeak using Arduino Mega and CC3000 shield with Adafruit CC3000 library. But I would like to use aRest library to drive a relay remotely. But I'm afraid there is some compatibility issue. It is true? Do you have some suggestion? Thank you in advance

marcoschwartz commented 8 years ago

Hum that's quite hard to tell like this, having never used ThingSpeak with Arduino. I think the best is simply to try and see if that works :)

zetalif commented 8 years ago

Hi Marco,

yes you are right! I've tried and I can send values to ThingSpeak without problem but I'm not able to send API command. The sketch in the following. As you can see in the in the Handle Rest Call I've to change client to client1 because of conflict with CC3000 library (I suppose). In any case when I try */led?params=0 or other commands nothings appears in my browser. Thank you for your help

/* Motor Shield L293 + CC3000 + Arduino Mega2650 + Strinity Sensor */

// Import required libraries

include

include

include

include

include

include

include <avr/wdt.h>

include

include

include "TSL2561.h"

include

// These are the pins for the CC3000 chip if you are using a breakout board

define ADAFRUIT_CC3000_IRQ 3

define ADAFRUIT_CC3000_VBAT 5

define ADAFRUIT_CC3000_CS 10

// Create CC3000 instance Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2); // Create aREST instance aREST_UI rest = aREST_UI();

// Your WiFi SSID and password

define WLAN_SSID "xxxxxxxxxxxxxx"

define WLAN_PASS "xxxxxxxxxxxxxx"

define WLAN_SECURITY WLAN_SEC_WPA2

// The port to listen for incoming TCP connections

define LISTEN_PORT xxx

// Server instance Adafruit_CC3000_Server restServer(LISTEN_PORT);

// DNS responder instance MDNSResponder mdns;

Adafruit_BMP085 bmp; TSL2561 tsl(TSL2561_ADDR_FLOAT); //num. step x giro = 360/step; lo step è riportato sul motore // 1 x M1/M2 e 2 x M3/M4 AF_Stepper motor(96, 1);

// Variables to be exposed to the API int Altitude; float Pressure; int Temperature; int ir, full;

// ThingSpeak parameters

define WEBSITE "api.thingspeak.com"

String apiKey = "xxxxxxxxxxxxx"; uint32_t ip;

void setup(void) {
pinMode (53,OUTPUT);

// Start Serial Serial.begin(115200);

// Create button to control pin 6 rest.button(53);

// Sensor

bmp.begin(); tsl.begin(); tsl.setGain(TSL2561_GAIN_16X); tsl.setTiming(TSL2561_INTEGRATIONTIME_13MS);

// Init variables and expose them to REST API

rest.variable("altitude",&Altitude); rest.variable("pressure",&Pressure); rest.variable("temperature",&Temperature); rest.variable("ir",&ir); rest.variable("full",&full);

rest.label("altitude"); rest.label("pressure"); rest.label("temperature"); rest.label("ir"); rest.label("full");

// Function to be exposed rest.function("led",ledControl);

// Give name and ID to device rest.set_id("xxx"); rest.set_name("xxxx");

// Set up CC3000 and get connected to the wireless network. if (!cc3000.begin()) { while(1); } if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) { while(1); } while (!cc3000.checkDHCP()) { delay(100); } Serial.println();

// Print CC3000 IP address. Enable if mDNS doesn't work //while (! displayConnectionDetails()) { // delay(1000); //}

// Start multicast DNS responder if (!mdns.begin("arduino", cc3000)) { while(1); }

// Start server restServer.begin(); Serial.println(F("Listening for connections..."));

// Enable watchdog wdt_enable(WDTO_4S); }

void loop() {

// Handle any multicast DNS requests mdns.update();

// Handle REST calls. Adafruit_CC3000_ClientRef client1 = restServer.available(); rest.handle(client1); wdt_reset();

// Check connection, reset if connection is lost if(!cc3000.checkConnected()){while(1){}} wdt_reset(); // Sensor readings

Altitude = bmp.readAltitude(101500); Pressure = bmp.readPressure(); Temperature = bmp.readTemperature();

uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE); uint32_t lum = tsl.getFullLuminosity(); ir = lum >> 16; full = lum & 0xFFFF;

Get the website IP & print it ip = 0; Serial.print(WEBSITE); Serial.print(F(" -> ")); while (ip == 0) { if (!cc3000.getHostByName(WEBSITE, &ip)) { Serial.println(F("Couldn't resolve!")); } delay(500); } cc3000.printIPdotsRev(ip);

// Send request Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80); if (client.connected()) {

String postStr = apiKey;
       postStr +="&field1=";
       postStr += String(Pressure);
       postStr +="&field2=";
       postStr += String(Temperature);
       postStr +="&field3=";
       postStr += String(full);
       postStr +="&field4=";
       postStr += String(ir);
       postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);

  } else {
Serial.println(F("Connection failed"));    
return;

}

Serial.println(F("-------------------------------------")); while (client.connected()) { while (client.available()) { char c = client.read(); Serial.print(c); } } client.close(); Serial.println(F("-------------------------------------"));

Serial.println(F("\n\nDisconnecting")); cc3000.disconnect();

Wait 20 seconds until next update delay(20000);

} // Custom function accessible by the API int ledControl(String command) {

// Get state from command int state = command.toInt(); motor.step(150, FORWARD, MICROSTEP); digitalWrite(53,state); delay(1000); return state; }

zetalif commented 8 years ago

hoopss!!!! sorry I've fault to copy the code. You can see I've used also aRest_UI ; same results. Sorry again regards

 /* 
 Motor Shield L293 + CC3000 + Arduino Mega2650 + Strinity Sensor
  */

// Import required libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <CC3000_MDNS.h>
#include <aREST.h>
#include <aREST_UI.h>
#include <avr/wdt.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "TSL2561.h"
#include <AFMotor.h>

// These are the pins for the CC3000 chip if you are using a breakout board
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// Create CC3000 instance
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                     SPI_CLOCK_DIV2);
// Create aREST instance
aREST_UI rest = aREST_UI();

// Your WiFi SSID and password                                         
#define WLAN_SSID       "xxxxxxxxxxxxxx"
#define WLAN_PASS       "xxxxxxxxxxxxxx"
#define WLAN_SECURITY   WLAN_SEC_WPA2

// The port to listen for incoming TCP connections  
#define LISTEN_PORT           200

// Server instance
Adafruit_CC3000_Server restServer(LISTEN_PORT);

// DNS responder instance
MDNSResponder mdns;

Adafruit_BMP085 bmp;
TSL2561 tsl(TSL2561_ADDR_FLOAT); 
AF_Stepper motor(96, 1);

// Variables to be exposed to the API
int Altitude;
float Pressure;
int Temperature;
int ir, full;

// ThingSpeak parameters
#define WEBSITE  "api.thingspeak.com"
String apiKey = "xxxxxxxxxxxxx";
uint32_t ip;

void setup(void)
{  
 pinMode (53,OUTPUT);

 // Start Serial
 Serial.begin(115200);

// Create button to control pin 6
 rest.button(53);

// Sensor

bmp.begin();
tsl.begin();
tsl.setGain(TSL2561_GAIN_16X);
tsl.setTiming(TSL2561_INTEGRATIONTIME_13MS); 

// Init variables and expose them to REST API

  rest.variable("altitude",&Altitude);
  rest.variable("pressure",&Pressure);
  rest.variable("temperature",&Temperature);
  rest.variable("ir",&ir);
  rest.variable("full",&full);

  rest.label("altitude");
  rest.label("pressure");
  rest.label("temperature");
  rest.label("ir");
  rest.label("full");

  // Function to be exposed
  rest.function("led",ledControl);

  // Give name and ID to device
  rest.set_id("xxx");
  rest.set_name("xxxx");

  // Set up CC3000 and get connected to the wireless network.
  if (!cc3000.begin())
  {
  while(1);
  }
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
  while(1);
  }
  while (!cc3000.checkDHCP())
 {
 delay(100);
 }
Serial.println();

 // Print CC3000 IP address. Enable if mDNS doesn't work
 //while (! displayConnectionDetails()) {
// delay(1000);
//}

// Start multicast DNS responder
if (!mdns.begin("arduino", cc3000)) {
while(1); 
}

// Start server
restServer.begin();
Serial.println(F("Listening for connections..."));

// Enable watchdog
wdt_enable(WDTO_4S);

 }

 void loop() {

// Handle any multicast DNS requests
mdns.update();

// Handle REST calls
Adafruit_CC3000_ClientRef client1 = restServer.available();
rest.handle(client1);
wdt_reset();

// Check connection, reset if connection is lost
if(!cc3000.checkConnected()){while(1){}}
wdt_reset();
// Sensor readings

Altitude = bmp.readAltitude(101500);
Pressure = bmp.readPressure();
Temperature = bmp.readTemperature();

uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE); 
uint32_t lum = tsl.getFullLuminosity();
ir = lum >> 16;
full = lum & 0xFFFF;

Get the website IP & print it
ip = 0;
Serial.print(WEBSITE); Serial.print(F(" -> "));
while (ip == 0) {
if (!cc3000.getHostByName(WEBSITE, &ip)) {
Serial.println(F("Couldn't resolve!"));
}
delay(500);
}
cc3000.printIPdotsRev(ip);

// Send request
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
if (client.connected()) {

String postStr = apiKey;
       postStr +="&field1=";
       postStr += String(Pressure);
       postStr +="&field2=";
       postStr += String(Temperature);
       postStr +="&field3=";
       postStr += String(full);
       postStr +="&field4=";
       postStr += String(ir);
       postStr += "\r\n\r\n";

  client.print("POST /update HTTP/1.1\n");
  client.print("Host: api.thingspeak.com\n");
  client.print("Connection: close\n");
  client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
  client.print("Content-Type: application/x-www-form-urlencoded\n");
  client.print("Content-Length: ");
  client.print(postStr.length());
  client.print("\n\n");
  client.print(postStr);

  } else {
 Serial.println(F("Connection failed"));    
 return;
 }

Serial.println(F("-------------------------------------"));
while (client.connected()) {
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}
client.close();
Serial.println(F("-------------------------------------"));

Serial.println(F("\n\nDisconnecting"));
cc3000.disconnect();

Wait 20 seconds until next update
delay(20000);
}

// Custom function accessible by the API
int ledControl(String command) {

// Get state from command
int state = command.toInt();
motor.step(150, FORWARD, MICROSTEP);
digitalWrite(53,state);
delay(1000);
return state;
}
marcoschwartz commented 8 years ago

Hello,

That's really difficult to say. I think that basically the commands you send to ThingSpeak are interfering with the behavior of the aREST API.

buxtehude04 commented 8 years ago

Hi friend,

Could you be so kind enough to help and showing me how i could use or call the wdt function for a code which should be executed in a Arduino Due board?

I need to use this resource because, I have not been able so far for implement a obligatory reset for synchronize a gprs shield, which only begin to answer at commands until i push down the reset button.

I tried implement differents circuits that generate and could hold the reset even if the board started to reset. Looking the reset signal through a osciloscope i could see the the signal generated by the annexed circuit in the reset pin of the board is identical to the reset signal generated pressing the reset button. I cant understand why the reset of the circuit can't do the same work that the manual reset.

My last resource is use the wdt function.

Thank you for your help.

Best Regards...

Brian

marcoschwartz commented 8 years ago

@buxtehude04 I answered on the other issue you opened :)