Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: Arduino and Unicode Strings like "\u00e1" on: August 14, 2012, 03:29:56 pm
Ok, That´s it. Works very well for decoding Twitter tweets from JSON format:

Code:
String convertUnicode(String unicodeStr){
  String out = "";
  int len = unicodeStr.length();
  char iChar;
  char* error;
  for (int i = 0; i < len; i++){
     iChar = unicodeStr[i];
     if(iChar == '\\'){ // got escape char
       iChar = unicodeStr[++i];
       if(iChar == 'u'){ // got unicode hex
         char unicode[6];
         unicode[0] = '0';
         unicode[1] = 'x';
         for (int j = 0; j < 4; j++){
           iChar = unicodeStr[++i];
           unicode[j + 2] = iChar;
         }
         long unicodeVal = strtol(unicode, &error, 16); //convert the string
         out += (char)unicodeVal;
       } else if(iChar == '/'){
         out += iChar;
       } else if(iChar == 'n'){
         out += '\n';
       }
     } else {
       out += iChar;
     }
  }
  return out;
}

A Serial.println():
Code:
---------------
From @Wheres_October (Tsuki~Chan)
*giggles* ^°^
#steampunk #zombies #smallthings #daymade http://t.co/r17d8bkf
Tue, 14 Aug 2012 19:18:56 +0000
2  Using Arduino / Programming Questions / Re: Arduino and Unicode Strings like "\u00e1" on: August 14, 2012, 02:53:04 pm
I'm getting closer ... ;o) only one char isn´t correct ...

Code:
#include <cstdlib>

String unicodeStr = "let\\u00C6s get some german umlauts like \\u00E4\\u00F6\\u00FC";

void setup() {
  Serial.begin(9600);
  
  /*
  
    Expected output:
    
    let´s get some german umlauts like äöü
    
  */
  Serial.println(convertUnicode(unicodeStr));
}

String convertUnicode(String unicodeStr){
  String out = "";
  int len = unicodeStr.length();
  char iChar;
  char* error;
  for (int i = 0; i < len; i++){
     iChar = unicodeStr[i];
     if(iChar == '\\'){ // got escape char
       iChar = unicodeStr[++i];
       if(iChar == 'u'){ // got unicode hex
         char unicode[6];
         unicode[0] = '0';
         unicode[1] = 'x';
         for (int j = 0; j < 4; j++){
           iChar = unicodeStr[++i];
           unicode[j + 2] = iChar;
         }
         long unicodeVal = strtol(unicode, &error, 16); //convert the string
         out += (char)unicodeVal;
       }
     } else {
       out += iChar;
     }
  }
  return out;
}

void loop(){}

Current output is:
Code:
letÆs get some german umlauts like äöü
3  Using Arduino / Programming Questions / Re: Arduino and Unicode Strings like "\u00e1" on: August 14, 2012, 02:27:56 pm
Hi Tom and thanks again! But I couldn´t get it working. Here´s my test case:

Code:

String unicodeStr = "let\\u00C6s get some german umlauts like \\u00E4\\u00F6\\u00FC";

void setup() {
  Serial.begin(9600);
 
  /*
 
    Expected output:
   
    let´s get some german umlauts like äöü
   
  */
  Serial.println(convertUnicode(unicodeStr));
}

String convertUnicode(String unicodeStr){
  String out = "";
  int len = unicodeStr.length();
  char iChar;
  char* error;
  for (int i = 0; i < len; i++){
     iChar = unicodeStr[i];
     if(iChar == '\\'){ // got escape char
       iChar = unicodeStr[++i];
       if(iChar == 'u'){ // got unicode hex
         char unicode[4];
         for (int j = 0; j < 4; j++){
           iChar = unicodeStr[++i];
           unicode[j] = iChar;
         }
         unsigned int integerValue = (unsigned int) strtol(unicode, &error, 4); //convert the string
         out += (char)integerValue;
       }
     } else {
       out += iChar;
     }
  }
  return out;
}

void loop(){}

Do you have any hints where I´m failing?

greetings André
4  Using Arduino / Programming Questions / Re: Arduino and Unicode Strings like "\u00e1" on: August 13, 2012, 05:30:54 pm
Hey, great! Thanks for these tips!
Du you have any suggestion for my Unicode problem? ^^ I don't know how to convert them. With PHP it would be easy, but I don't know how to do it with C++/arduino.

thx Sunny
5  Using Arduino / Programming Questions / Arduino and Unicode Strings like "\u00e1" on: August 13, 2012, 04:43:59 pm
Hi,

I´m fetching and parsing a JSON Response. Works quite well, but now I´m getting unicode characters like "\u00e1". How can I convert these with Arduino/C++?

greetings Sunny

This is my simple JSON "Parser":
Code:
void loop()
{
  if (client.connected()) {
    if (client.available()) {
     
      char inChar = client.read();
     
      if(inString){
       
        if(inChar == '\\'){
          escapeNextChar = true;
          currentValue += inChar;
        } else if(!escapeNextChar && inChar == '"'){
          inString = false;
         
          if(currentIdentifier == ""){
            currentIdentifier = currentValue;
            currentValue = "";
          } else {
            printKeyValue();
          }
         
        } else {
          escapeNextChar = false;
          currentValue += inChar;
        }
       
      } else if(inChar == '{'){
        //inObject = true;
        printKeyValue();
      } else if(inChar == '}'){
        //inObject = false;
        printKeyValue();
      } else if(inChar == '['){
        //inArray = true;
        printKeyValue();
      } else if(inChar == ']'){
        //inArray = false;
        printKeyValue();
      } else if(inChar == '"'){
        inString = true;
      } else if(inChar == ',') {
        //colon = true;
        printKeyValue();
      } else if(inChar == '\n') {
       
        printKeyValue();
       
      } else if(inChar == ' ') {
       
        printKeyValue();
       
      } else if(inChar == ':') {
        if(currentValue != ""){
          currentIdentifier = currentValue;
          currentValue = "";
        }
      } else {
        currentValue += inChar;
      }
     
    }
    else {if (millis() - lastAttemptTime > requestInterval) {
        gotResults = false;
       
        connectToServer();
      }
    }
  }
}

void printKeyValue(){
 
  if(currentIdentifier == "results"){
   
    gotResults = true;
   
  } else if(gotResults){
   
    if(currentIdentifier == "created_at"){
      currentTweetTime = currentValue;
    } else if(currentIdentifier == "from_user"){
      currentTweetUser = currentValue;
    } else if(currentIdentifier == "from_user_name"){
      currentTweetUserName = currentValue;
    } else if(currentIdentifier == "text"){
      currentTweetText = currentValue;
    }
   
    if(currentTweetText != ""){
     
      Serial.println("---------------");
      Serial.println("From @" + currentTweetUser + " (" + currentTweetUserName + ")");
      Serial.println(currentTweetText);
      Serial.println(currentTweetTime);
 
      currentTweetTime = "";
      currentTweetUser = "";
      currentTweetUserName = "";
      currentTweetText = "";
    }
  }
 
  currentIdentifier = "";
  currentValue = "";
}
6  Using Arduino / Programming Questions / Re: Help getting Tweener C++ working with arduino on: June 06, 2011, 05:27:09 am
From 0 to 180 to 0. The duration belongs to an analog input. 15 ms up to 5000 ms. Hm, the best way will be to write a simple function that handles the ramping based on current millis(). I thought I could use some library (the easy way ;o)), but seems there isn´t one.

thx for your help! :o)
André
7  Using Arduino / Programming Questions / Re: Help getting Tweener C++ working with arduino on: June 06, 2011, 04:54:31 am
Hm, that´s bad. Did anyone know a good tweening/ramping library? I need to tween/ramp intergers (floats are also good).

thx,
André
8  Using Arduino / Programming Questions / Re: Help getting Tweener C++ working with arduino on: June 06, 2011, 04:46:42 am
Hi Rob,

the one you posted is written in Flash, you are right. But the one I posted is written in C++ (a C++ port of the Flash Tweener) and should run on arduino, I think. But it won´t compile and I don´t know what exactly I have to change. ;o)

http://code.google.com/p/cpptweener/

greetings,
André
9  Using Arduino / Programming Questions / Help getting Tweener C++ working with arduino on: June 06, 2011, 03:45:15 am
Hi,

is there any way, to get this Library:

http://code.google.com/p/cpptweener/

working with arduino? I´ve put it inside the library folder, but at compile time, i get a lot of errors (list, vector, iostream).
I´m really no C++ developer. smiley-sad But i need a good tweening library. The one here isn´t complete: http://wiki.dataflow.ws/LibInteract smiley-sad

greetings,
André
10  Using Arduino / Networking, Protocols, and Devices / Re: Can bus on: February 13, 2011, 06:46:31 am
Why didn´t they write english? Bad ... :/
11  Using Arduino / Networking, Protocols, and Devices / Re: CAN-Bus ECU Reader demo sketch on: February 12, 2011, 01:55:25 pm
Got it working with this Library / Sketch:

http://code.google.com/p/skpang/downloads/detail?name=Canbus_v2.zip

greetings Sunny
12  Using Arduino / Networking, Protocols, and Devices / Re: CAN-Bus ECU Reader demo sketch on: February 06, 2011, 06:36:14 pm
Did anyone use this shield with success? If so, on which Arduino board, which Arduino software version and did you modify something inside the Canbus and/or MCP2515 Libraries?
13  Using Arduino / Networking, Protocols, and Devices / Re: CAN-Bus ECU Reader demo sketch on: February 06, 2011, 06:32:03 pm
Btw. I'm using Arduino v0021. Could this problem be caused by the SPI divider bug? Should I update to v0022 or downgrade to v0017? What Version did the guy in the shield's demo video use?
14  Using Arduino / Networking, Protocols, and Devices / CAN-Bus ECU Reader demo sketch on: February 06, 2011, 03:30:36 pm
Hi,

I´m trying to run the CAN-Bus ECU Reader demo sketch from here: http://www.skpang.co.uk/catalog/product_info.php?products_id=706

It starts and prints "CAN Init ok", but than it freezes. I´ve done some debugging and got the line where it breaks. It´s this line:

mcp2515_check_message()

inside the Canbus.cpp

I really don´t know why this is happen and how to fixe it. The CAN-board was connected to an 2010 Volkswagon.
Any hints in the right direction?

greetings Sunny
15  Forum 2005-2010 (read only) / Troubleshooting / Re: Error in File WProgram.h on: December 22, 2008, 11:48:13 am
Hm.. both the max() / min() function calls doesn't work. if i write:

Code:
inline void Quadrature::maximum(int max) {
    _max = max;
    _usingmax = 1;

    //  adjust position if higher than new maximum
    _position = _position < max ? _position : max;
}

instead of:

Code:
inline void Quadrature::maximum(int max) {
    _max = max;
    _usingmax = 1;

    //  adjust position if higher than new maximum
    _position = min(_position, max);
}

all works fine. Is this an Arduino bug? Or do i just need to include one more library? (I've tried to include <math.h> with no effect)

thx sunny
Pages: [1] 2 3 4