Ich will einen Floatwert (Temperaturwert) mit einem SIM800L Modul an meinen Webserver senden. Leider kann ich irgendwie nur int senden, aber keine floats. Wie kann ich erreichen, dass der Float trotzdem ankommt. Bsp: Ich sende Wert 20.6, erhalte aber 20. Wenn ich anstatt der Variable (x) die Zahl 20.6 direkt einsetze, kommt 20.6 an. Bitte helft mir.
Code:
#include "SIM900.h"
#include <SoftwareSerial.h>
//#include "inetGSM.h"
//#include "sms.h"
//#include "call.h"
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to communicate with SIM900 through AT commands.
//InetGSM inet;
//CallGSM call;
//SMSGSM sms;
int numdata;
char inSerial[40];
int i=0;
float x = 4.3;
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change :
const long interval = 10000; // interval at which to blink (milliseconds)
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
gsm.SimpleWriteln("AT+CIPSHUT");
gsm.SimpleWriteln("AT+CSQ");
gsm.SimpleWriteln("AT+CIPMUX=0");
gsm.SimpleWriteln("AT+CSTT=\"gprs.swisscom.ch\",\"\",\"\"");
delay(24000);
gsm.SimpleWriteln("AT+CIICR");
delay(4000);
gsm.SimpleWriteln("AT+CIFSR");
delay(4000);
gsm.SimpleWrite("AT+CIPSTART=\"UDP\",\"");
gsm.SimpleWrite("xx.xx-box.ch");
gsm.SimpleWrite("\",");
gsm.SimpleWriteln("8888");
delay(10000);
};
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
gsm.SimpleWriteln("AT+CIPSEND");
delay(1000);
gsm.SimpleWriteln(x);
delay(100);
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
delay(10);
x = x + 1;
}
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
};
void serialhwread(){
i=0;
if (Serial.available() > 0){
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")){
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")){
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
}
else{
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread(){
gsm.SimpleRead();
}
//#include "sms.h"
//#include "call.h"
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to communicate with SIM900 through AT commands.
//InetGSM inet;
//CallGSM call;
//SMSGSM sms;
int numdata;
char inSerial[40];
int i=0;
char x = 4.3;
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change :
const long interval = 10000; // interval at which to blink (milliseconds)
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
gsm.SimpleWriteln("AT+CIPSHUT");
gsm.SimpleWriteln("AT+CSQ");
gsm.SimpleWriteln("AT+CIPMUX=0");
gsm.SimpleWriteln("AT+CSTT=\"gprs.swisscom.ch\",\"\",\"\"");
delay(4000);
gsm.SimpleWriteln("AT+CIICR");
delay(4000);
gsm.SimpleWriteln("AT+CIFSR");
gsm.SimpleWrite("AT+CIPSTART=\"UDP\",\"");
gsm.SimpleWrite("xx.xxx-box.ch");
gsm.SimpleWrite("\",");
gsm.SimpleWriteln("8888");
delay(10000);
};
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
gsm.SimpleWriteln("AT+CIPSEND");
delay(1000);
gsm.SimpleWriteln(x);
delay(100);
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
delay(10);
x = x + 1;
}
serialhwread();
//Read for new byte on NewSoftSerial.
serialswread();
};
void serialhwread(){
i=0;
if (Serial.available() > 0){
while (Serial.available() > 0) {
inSerial[i]=(Serial.read());
delay(10);
i++;
}
inSerial[i]='\0';
if(!strcmp(inSerial,"/END")){
Serial.println("_");
inSerial[0]=0x1a;
inSerial[1]='\0';
gsm.SimpleWriteln(inSerial);
}
//Send a saved AT command using serial port.
if(!strcmp(inSerial,"TEST")){
Serial.println("SIGNAL QUALITY");
gsm.SimpleWriteln("AT+CSQ");
}
else{
Serial.println(inSerial);
gsm.SimpleWriteln(inSerial);
}
inSerial[0]='\0';
}
}
void serialswread(){
gsm.SimpleRead();
}
Definiere ein char array.
"Char meinArray[20];"
Und fülle das Array mit einem Text.
meinArray = "12.7";
Die 20 ist die maximale (-1) Anzahl Zeichen deines Strings.
So sollte es funktionieren.
Im übrigen sind das Grundlagen die du reichlich im Web findest.