rest.variable() freezes arduino

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jacksonhead08
 
Posts: 2
Joined: Sat Oct 11, 2014 7:07 am

rest.variable() freezes arduino

Post by jacksonhead08 »

Hi Everybody!

I just started using the CC3000 wifi breakout board. My code works as long as i dont use rest.variable() function. When i apply the function the ADC stops working (in the loop function i wrote an LED brightness changer code, and the LED's bright wont change).
The code is basicly this example:
https://github.com/openhomeautomation/CC3000_REST

The code:

Code: Select all

// Import required libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <CC3000_MDNS.h>
#include <aREST.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);

// Your WiFi SSID and password                                         
#define WLAN_SSID       "****"
#define WLAN_PASS       "****"
#define WLAN_SECURITY   WLAN_SEC_WEP

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

// Create aREST instance
aREST rest = aREST();

// Server instance
Adafruit_CC3000_Server restServer(LISTEN_PORT);

// DNS responder instance
MDNSResponder mdns;

void setup(void)
{  
  Serial.begin(115200);
  
  // Set up CC3000 and get connected to the wireless network.
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }
  Serial.println();
  
  // Print CC3000 IP address
  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..."));
}

int sensorvalue=0, outputvalue=0;
int seg=1;

void loop() 
{  
  // Handle any multicast DNS requests
  mdns.update();
  
  // Handle REST calls
  Adafruit_CC3000_ClientRef client = restServer.available();
  rest.handle(client);
  
  sensorvalue = analogRead(A0);
  outputvalue = map(sensorvalue, 780, 0, 0, 255);
  analogWrite(9, outputvalue); //Changes LED brightness
  
  rest.variable("seg", &seg);
}

// Print connection details of the CC3000 chip
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}
Any ideas why it happens?

User avatar
marco26fr
 
Posts: 38
Joined: Sat Jul 28, 2012 5:25 am

Re: rest.variable() freezes arduino

Post by marco26fr »

Hello,

I am Marco Schwartz, the creator of the aREST library. First thanks for using my library for your project! About your problem: it seems that you are using a deprecated version of the project: I know put everything in a nice Arduino library that you can find here:

https://github.com/marcoschwartz/aREST

Try basing your project on the CC3000 example included in the library, and let me know how it goes. Also, make sure to use the Arduino IDE 1.5.7, which produces a much more compact sketch compared to the 1.0.5. I think you could have a RAM problem as well. Looking forward to hearing from you!

User avatar
jacksonhead08
 
Posts: 2
Joined: Sat Oct 11, 2014 7:07 am

Re: rest.variable() freezes arduino

Post by jacksonhead08 »

Dear Marco!

IT WORKS PERFECTLY :DDD

First i'd like to thank you for your help. I downloaded the library you suggested and i'm using it from "Documents\Arduino\libraries\aREST-master". My IDE's version is 1.5.8. I think the problem was that i got the example scatch from the youtube video you posted about the Rest API (and it's old? :) ). Now what i did was run the example scatch from the Arduino IDE (File -> Examples -> aREST-master -> Wifi_CC3000) and after it downloaded to the board i put "http://my_ip_adress/humidity" to the browser and it printed out the pre-definied value of the humidity integer.

Thank you very much again, i already began to work with it! :D

User avatar
marco26fr
 
Posts: 38
Joined: Sat Jul 28, 2012 5:25 am

Re: rest.variable() freezes arduino

Post by marco26fr »

You're welcome, I am glad that you can use the project now!

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”