-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python calls to Library #29
Comments
Hello, thanks for using my library! Actually I had some success with calls from Python, but using the pycurl module (http://pycurl.sourceforge.net/). I used it for automated tests, but now I moved to Node.js for that part. Here is a function I used to make cURL calls using pycurl:
Then you can do calls with: or to get data back using the json module:
Let me know if it works! |
I believe there is a problem with the arduino script. We get a message of
Hello, thanks for using my library! Actually I had some success with calls from Python, but using the pycurl module (http://pycurl.sourceforge.net/). I used it for automated tests, but now I moved to Node.js for that part.Here is a function I used to make cURL calls using pycurl:def curl_call(target, command):buf = StringIO.StringIO()c = pycurl.Curl() |
In that case it looks more like an Arduino than a Python problem indeed. Could you give me:
Also make sure you have the latest versions of the CC3000 library & of the aREST library. Thanks! |
The board is the uno but I do have a Mega2560The IDE is the Arduino 1.5.8 because you had stated that I needed the upgraded version.
In that case it looks more like an Arduino than a Python problem indeed. Could you give me:
|
I guess the problem is the IDE indeed. There are many known problems with the CC3000 library + the 1.5.8 IDE. Try with the 1.5.7 and let me know if it works. You can get it from: http://arduino.cc/en/Main/OldSoftwareReleases |
I had the same problem, also using arduino 1.5.8, I followed |
Thanks Guys I have made the changes and I will try it later. I will let you know what happened. |
I uninstalled the Arduino 1.5.8 IDE. I then installed the 1.5.7 version from the link above. I then changed the socket.cpp file by adding #define SEND_NON_BLOCKING 1 above #define SOCKET_OPEN_PARAMS_LEN (12) . {"temperature": 28, "id": "008", "n when "192.168.0.100/temperature" is used in the URL. I get the result: {"humidity": 40, "id": "008", "name when i use humidity instead of temperature. This looks like only 35 characters can be sent is there a variable that would be set to only allow a certain amount of characters to be sent in json format? Here is the debug info I am getting because I set debug to 1. GET / Added to buffer: {" State of buffer at the end: HTTP/1.1 200 OK {"temperature": 28, "id": "008", "name": "mighty_cat", "connected": true} Sending buffer: HTTP/1.1 200 OK |
Strange, according to the debug part everything works fine, but not in your browser. What browser are you using for the test? Can you try with another one? I have success with Chrome & Safari for Mac. |
I have used the chromium browser with the raspberry pi and I also hit it with my windows machine with IE and Chrome. It all shows the same message with only 35 characters.
Strange, according to the debug part everything works fine, but not in your browser. What browser are you using for the test? Can you try with another one? I have success with Chrome & Safari for Mac.— |
Thanks for the info, I will try it again with the browser you mentioned and keep you updated! |
Thank you for all the help.
Thanks for the info, I will try it again with the browser you mentioned and keep you updated!— |
Thank you everyone that helped. We figured it out. If you change the sendBuffer(client,64,1000); call you will get the whole json message. We first worked with the 3rd parameter and hoped that the delay would let the whole message get sent but it looks like the 2nd and 3rd parameter work together. The best result was with this call sendBuffer(client,64,1000); in the "void handle(Adafruit_CC3000_ClientRef& client) " method. |
Interesting, I will test that on the Mega I have available. Can you submit a pull request with your solution? Thanks a lot! |
Can I send you the file because I don't know how to submit a pull request and I don't want to create a problem with your code. If you have steps to submit it I am all ears. Jade Fischer,
Interesting, I will test that on the Mega I have available. Can you submit a pull request with your solution? Thanks a lot!— |
Sure, just send it over to: marcolivier.schwartz@gmail.com. I will then test it & push the changes. I need to make sure it doesn't interfere with the behavior of the library with other boards. Thanks! |
I sent the file but here is the only change and it is the 2 parameters going into the sendBuffer() call.
Sure, just send it over to: marcolivier.schwartz@gmail.com. I will then test it & push the changes. I need to make sure it doesn't interfere with the behavior of the library with other boards. Thanks!— Written in 2014 by Marco Schwartz under a GPL license. Version 1.9.4 Changelog: Version 1.9.4: Bug fixes & added support for configuring analog pints as digital outputs Version 1.8: Speedup of the library (answers 2.5x faster with the CC3000 WiFi chip) Version 1.7.5: Reduced memory footprint of the library Version 1.6: Added compatibility with the Arduino Yun Version 1.5: Size reduction, and added compatibility with Adafruit BLE Version 1.4: Added authentification with API key Version 1.3: Added support for the Ethernet shield Version 1.2: Added support of Serial communications Version 1.1: Added variables & functions support Version 1.0: First working version of the library */ // Include Arduino header // Which board? // Size of name & ID // Debug mode // Use light answer mode // Default number of max. exposed variables // Default number of max. exposed functions class aREST { public: status_led_pin = 255; // Set status LED // Set variables // Set pin as output // Glow status LED if(status_led_pin != 255){ // Send HTTP headers for Ethernet & WiFi addToBuffer(F("HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Methods: POST, GET, PUT, OPTIONS\r\nContent-Type: application/json\r\nConnection: close\r\n\r\n")); // Reset variables after a request index = 0; } // Handle request with the Adafruit CC3000 WiFi library if (client.available()) {
} // Handle request with the Arduino Yun if (client.available()) {
} // Handle request with the Adafruit BLE board if (serial.available()) {
} // Handle request for the Arduino Ethernet shield if (client.available()) {
} // Handle request for the Arduino Ethernet shield if (client.available()) {
} #elif defined(CORE_TEENSY) if (serial.available()) {
} #else if (serial.available()) {
} void handle(char * string) { // Process String // Reset variables for the next command void handle_proto(char * string) {
} // Send command template // Check if there is data available to read
} // Send command void process(char c){ // Check if we are receveing useful data and process it
}
} bool send_command(bool headers) { if (DEBUG_MODE) { // Start of message // Mode selected
} // Digital selected
} // Analog selected
}
} // Variable selected
} // Function selected
} if (command == 'r') {
} if (command == 'i') { // End of message else {
} if (DEBUG_MODE) { // End here void variable(char * variable_name, int *variable){ int_variables[variables_index] = variable; } void function(char * function_name, int (*f)(String)){ functions_names[functions_index] = function_name; // Set device ID strcpy(id,device_id); // Set device name strcpy(name, device_name); // Set device name device_name.toCharArray(name, NAME_SIZE); // Set device ID device_id.toCharArray(id, NAME_SIZE); // Add to output buffer if (DEBUG_MODE) { for (int i = 0; i < strlen(toAdd); i++){ // Add to output buffer char number[10]; addToBuffer(number); // Add to output buffer if (DEBUG_MODE) { uint8_t idx = 0; const char PROGMEM *p = (const char PROGMEM *)toAdd; template if (DEBUG_MODE) { // Max iteration // Send data
}
} char * getBuffer() { void resetBuffer(){ private: char name[NAME_SIZE]; // Output buffer // Status LED // Variables arrays // Functions array |
Hi, thanks for the details on the changes. I finally got myself a working Arduino Mega to make some tests. Unfortunately I couldn't reproduce the issue you are having, when I call the API from a browser or an app it works just fine with the current state of the library: {"temperature": 22, "id": "001", "name": "wifi", "connected": true} The issue I have with the change you proposed is that it nearly doubles the response time of the board (tested with Postman for Chrome), so I can't push this changes. I would really check again that you are using the latest versions of all libraries, the right Arduino IDE (1.5.7). I would also check that you are using the latest firmware for the CC3000 chip. To update it, just use the driverpatch_xxx sketch included in the Adafruit library. Let me know if that helps! |
I will check to see if everything is the correct versions. Jade Fischer,
Thank you for all the help.
Thanks for the info, I will try it again with the browser you mentioned and keep you updated!— |
Closing this now :) |
First of all thank you for the libraries and the documentation, they have been very helpful. I have an issue though. I am trying to make rest calls to the CC3000 and it doesn't seem to work even though I can ping it. I have also created my own variables and were able to retrieve them through the URL. EX. http://192.168.0.100/temperature. I want to access it through Python so I tried:
import urllib2
response = urllib2.urlopen('http://python.org/')
html = response.read()
print html
We even tried to output this to a file and retrieve it with a browser and we can't retrieve anything from the CC3000 it just hangs. This python code will work though. We were able to get html pages from the Raspberry Pi web server in this manner.
I know java script might work but I really want to use Kivy with python and retrieve my variables from the CC3000 so I can display them with python. Any help would be appreciated.
The text was updated successfully, but these errors were encountered: