Hi,
For christmas, my lovely girlfriend gave me a spark core and some others pieces to make an awesome autonomous bot.
The goal is to have it controled by my tel and a java IA app.
For now he is controlled by the user, and i try to bring back some sensors data to display it on the smartphone.
I use UDP as communication protocol, it work fine, the command are reactiv and all, but i have a probleme with the sensors reading.
I think it’s something with the conversion from float to unsigned char[] to make it go in an UDP packet, i’m a Java coder and not used to this kind of low level issues, plus i have never did C
Here is my reading code
Udp.read(recbuf, pp >= 7 ? 7 : pp);
String mess = "";
for (int i = 0; i < 7; i++) {
mess += recbuf[i];
}
//Serial.println(mess + " <= boffer ");
// Ignore other chars
//Udp.flush();
//Store sender ip and port
IPAddress ipAddress = Udp.remoteIP();
int port = Udp.remotePort();
int reading;
double voltage;
char sep[] = {':'};
strcpy(sendbuff, sep);
reading = analogRead(axeX);
voltage = (reading * 3.3) / 4095;
float axeXvalue = (voltage /0.55) -3;
char axeXvalueB[8]; //= static_cast<unsigned char*>(axeZvalue);
snprintf(axeXvalueB, sizeof(axeXvalueB), "%g", axeXvalue);
strcat(sendbuff, axeXvalueB);
strcat(sendbuff, sep);
reading = analogRead(axeY);
voltage = (reading * 3.3) / 4095;
float axeYvalue = (voltage /0.55) -3;
char axeYvalueB[8];
snprintf(axeYvalueB, sizeof(axeYvalueB), "%g", axeYvalue);
strcat(sendbuff, axeYvalueB);
strcat(sendbuff, sep);
reading = analogRead(axeZ);
voltage = (reading * 3.3) / 4095;
float axeZvalue = (voltage /0.55) -3;
char axeZvalueB[8];
snprintf(axeZvalueB, sizeof(axeZvalueB), "%g", axeZvalue);
strcat(sendbuff, axeZvalueB);
//strcat(sendbuff, sep);
//float irValue = lectureTension();
//char irValueB[4];// = static_cast<unsigned char*>(irValue);
//snprintf(irValueB, sizeof(irValueB), "%f", irValue);
//dtostrf(irValueB, sizeof(irValueB), 3, irValue)
//strcat(sendbuff, irValueB);
// Echo back data to sender
Udp.beginPacket(ipAddress, port);
Udp.write(reinterpret_cast<unsigned char*>(sendbuff), sizeof(sendbuff));
// Echo back data to sender
//Udp.beginPacket(ipAddress, port);
//Udp.write(recbuf, 7);
Udp.endPacket();
As you can see it, the process is complicated, and possibly uselessly complicated. I did it from diverse post i found all over the net, but it’s complicated to sort all the response since Spark is not exactly C, neither Arduino.
It’s over complicated, and it don’t work as intended. The reading are from an accelerometer, i’m trying to get the value in G, wich i can see by publishing it in the cloud (it look like 0.0012234) but on the smartphone the char[] contains “:0i0:1-0:0O0:” for example where it should be “:0.001234:0.012332:0.002121” for example
So i need your help, can you point me a complete tutorial working tutorial to solve my problem, or at least an hint on where to search would be cool.
If you want i can post more informations about my project. I planned to do a complete explanation with Spark and android code, and the schematics if you think someone can be interested.
Cordialy
Arfost