Closed probonopd closed 8 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!
I managed to get it to run but it is confusing that there are different versions of the code using the same version number.
You mean because aREST UI has a different version number compared to aREST ?
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.
Closing this, I'll be careful about version numbers in the future :)
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
Hi Zetalif, can you give me details about the error? Thanks!
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
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
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 :)
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
// These are the pins for the CC3000 chip if you are using a breakout board
// 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
// The port to listen for incoming TCP connections
// 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
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; }
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;
}
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.
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
@buxtehude04 I answered on the other issue you opened :)
Cannot compile on ESP8266
I am using the latest http://github.com/esp8266/Arduino from git.