Capo d'Orlando
Offline
Sr. Member
Karma: 0
Posts: 305
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
|
 |
« on: January 20, 2013, 01:00:37 pm » |
Ciao a tutti ! In allegato trovate gli sketch. Quando faccio la verifica dello sketch "ntx2_sensore" l'IDE restituisce questo errore: (In fondo a questa pagina c'è lo sketch originale per il trasmettitore ntx2: http://ukhas.org.uk/guides:linkingarduinotontx2) cannot convert 'float' to 'const char*' for argument '2' to 'int sprinf(char*, const char*, ...)' La stringa "incriminata" è questa: sprintf(datastring, ds18b20.getTempCByIndex(0)); Quando l'originale era così: sprintf(datastring, "testo"); Mentre, quando faccio la verifica dello sketch "sms_sensor" esce: (Ecco la pagina della libreria del GSM Shield: http://code.google.com/p/gsm-shield-arduino/downloads/list) no matching function for call to 'SMSGSM::SendSMS(const char [11], float)' La stringa "incriminata" è questa: sms.SendSMS("3331234567", ds18b20.getTempCByIndex(0)); Quando l'originale era così: sms.SendSMS("3331234567", "testo"); Se lascio la stringa originale la compilazione avviene correttamente, se al posto del testo metto la variabile della temperatura (del sensore DS18B20), esce l'errore ! Sicuramente ho sbagliato ad impostare le stringhe, ma non riesco a capire come le posso sistemare ! Sapete come sistemare ciò ?  Grazie !
|
|
|
|
« Last Edit: January 20, 2013, 01:07:32 pm by anerDev »
|
Logged
|
|
|
|
|
Forum Moderator
Italy
Offline
Brattain Member
Karma: 219
Posts: 16499
Don't know what I do
|
 |
« Reply #1 on: January 20, 2013, 01:51:17 pm » |
sprintf(datastring, ds18b20.getTempCByIndex(0)); Si aspetta una stringa mentre tu probabilmente gli stai passando un valore numerico. Devi vedere che valore restituisce il metodo getTempCByIndex. Alternativamente puoi usare dtoprintf per convertire un numero in char* char datastring[10]; float x = ds18b20.getTempCByIndex(0); dtostrf(x, numero_cifre, numero_decimali, datastring);
|
|
|
|
|
Logged
|
|
|
|
|
Capo d'Orlando
Offline
Sr. Member
Karma: 0
Posts: 305
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
|
 |
« Reply #2 on: January 20, 2013, 02:17:05 pm » |
La stringa ds18b20.getTempCByIndex(0) dà il valore assoluto della temperatura, esempio "18.16" Non ho capito come devo modificare il blocco: sprintf(datastring, "testo"); // Puts the text in the datastring unsigned int CHECKSUM = gps_CRC16_checksum(datastring); // Calculates the checksum for this datastring char checksum_str[6]; sprintf(checksum_str, "*%04X\n", CHECKSUM); strcat(datastring,checksum_str); :/
|
|
|
|
|
Logged
|
|
|
|
|
Forum Moderator
Italy
Offline
Brattain Member
Karma: 219
Posts: 16499
Don't know what I do
|
 |
« Reply #3 on: January 20, 2013, 02:27:18 pm » |
Non ho capito come devo modificare il blocco:
Guarda qui: char datastring[10]; float x = ds18b20.getTempCByIndex(0); dtostrf(x, numero_cifre, numero_decimali, datastring); PS: mi ero dimenticato dell'altro errore. no matching function for call to 'SMSGSM::SendSMS(const char [11], float)' Ti dice che non trova una funzione che corrisponda a quella chiamata. Siccome gli allegati non funzionano sul forum da un paio di giorni, non posso aprire lo sketch per cui devi controllare se: la libreria l'hai inclusa; se hai istanziato la classe SMSGSM, se la stai chiamando col metodo giusto, se gli stai passando i parametri che vuole (una stringa di char ed un float).
|
|
|
|
|
Logged
|
|
|
|
|
Capo d'Orlando
Offline
Sr. Member
Karma: 0
Posts: 305
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
|
 |
« Reply #4 on: January 20, 2013, 05:21:42 pm » |
Aspettando che sistemino il problema del download degli allegati, puoi scaricare gli sketch da qua: https://www.dropbox.com/s/uq2cs8dgftpniu3/sketch.zipSe metto le stringhe originali non ho nessuno problema, se modifico la parte "testo" con la funzione che richiama il valore della temperatura ho problemi, quindi non penso che sia un problema di richiami. numero_cifre deve essere un numero ? Quindi qualcosa del genere ? float temperatura = ds18b20.getTempCByIndex(0); dtostrf(temperatura, 2, 2, datastring); Inoltre questio blocco dove lo devo piazzare o meglio, come lo integro nel blocco sprintf(datastring, "testo"); // Puts the text in the datastring unsigned int CHECKSUM = gps_CRC16_checksum(datastring); // Calculates the checksum for this datastring char checksum_str[6]; sprintf(checksum_str, "*%04X\n", CHECKSUM); strcat(datastring,checksum_str); Sto navigando in acque cieche ! :/
|
|
|
|
|
Logged
|
|
|
|
|
Forum Moderator
Italy
Offline
Brattain Member
Karma: 219
Posts: 16499
Don't know what I do
|
 |
« Reply #5 on: January 20, 2013, 05:37:48 pm » |
numero_cifre deve essere un numero ? Quindi qualcosa del genere ? float temperatura = ds18b20.getTempCByIndex(0); dtostrf(temperatura, 2, 2, datastring); numero_cifre rappresenta il numer complessivo delle cifre da gestire. Se vuoi 3.2 (3 interi e 2 decimal) ad esempio devi mettere 5. Inoltre questio blocco dove lo devo piazzare o meglio, come lo integro nel blocco sprintf(datastring, "testo"); // Puts the text in the datastring unsigned int CHECKSUM = gps_CRC16_checksum(datastring); // Calculates the checksum for this datastring char checksum_str[6]; sprintf(checksum_str, "*%04X\n", CHECKSUM); strcat(datastring,checksum_str); Sto navigando in acque cieche ! :/ Il tuo problema non era questo codice? sprintf(datastring, ds18b20.getTempCByIndex(0)); Questo codice lo sostituisci con quello che ti ho postato
|
|
|
|
|
Logged
|
|
|
|
|
Capo d'Orlando
Offline
Sr. Member
Karma: 0
Posts: 305
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
|
 |
« Reply #6 on: January 21, 2013, 10:34:33 am » |
Funziona ! Con una sola variabile ! =D L'ho impostato così: ds18b20.requestTemperatures(); float temperatura = ds18b20.getTempCByIndex(0); dtostrf(temperatura, 2, 2, datastring); unsigned int CHECKSUM = gps_CRC16_checksum(datastring); // Calculates the checksum for this datastring char checksum_str[6]; sprintf(checksum_str, "*%04X\n", CHECKSUM); strcat(datastring,checksum_str);
rtty_txstring (datastring); delay(2000); In questo modo funziona perfettamente, ovvero via radio mi arriva la temperatura. Ora cerco di capire come concatenare più variabili. Per quanto riguarda il secondo sketch, quell'errore esce solamente se modifico la stringa originale "testo" con la variabile, non penso che sia un problema di richiami. Cosa può essere ? Grazie per l'aiuto !
|
|
|
|
|
Logged
|
|
|
|
|
Forum Moderator
Italy
Offline
Brattain Member
Karma: 219
Posts: 16499
Don't know what I do
|
 |
« Reply #7 on: January 21, 2013, 01:40:40 pm » |
2° errore: Scusa, ho travisato io. Tu gli passi una stringa ed un float, mentre lui invece vuole 2 stringhe, quindi il problema è che anche in questo caso devi convertire il risultato di ds18b20.getTempCByIndex(0) in string.
|
|
|
|
|
Logged
|
|
|
|
|
Capo d'Orlando
Offline
Sr. Member
Karma: 0
Posts: 305
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
|
 |
« Reply #8 on: January 21, 2013, 04:56:06 pm » |
Per il primo problema, ho trovato la soluzione: char msg[1000]; int temp = ds18b20.getTempCByIndex(0); int hum = dht.readHumidity(); int pres = mpl115a2.getPressure(); snprintf(msg, 1000, "%d *C | %d %% | %d kPa \n", temp, hum, pres); rtty_txstring(msg); Invece per il problema dell'OMS domani cerco di risolvere tutto, sempre se il tempo migliora ed il gps si aggancia !  A domani e grazie !
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 9
Posts: 2192
Arduino rocks
|
 |
« Reply #9 on: January 21, 2013, 08:00:30 pm » |
http://digilander.libero.it/uzappi/C/librerie/funzioni/printf.htmlsprintf prende un numero minimo di 3 argomenti, il primo è un puntatore a char o un array di dimensioni adeguate, il secondo è un cost char* che permette di specificare la string format, il terzo o quarto, quinto ecc, sono variabili di qualunque tipo. L'errore : cannot convert 'float' to 'const char*' for argument '2' to 'int sprinf(char*, const char*, ...)' Non posso convertire float a const char * per l'argomento 2, per int sprintf(char*, const char* , ...) Es: float temp = 20.2; char buff[6]; sprintf(buff, "%2.2f\n", temp);
Questo codice converte il float temp in formato stringa secondo il formato specificato con %2.2f. Il contenuto di buff sarà 20.2\n\0. buff grande sei caratteri compreso il fine stringa \0. Sia \n \0 \t ecc sono sequenze di escape, da considerare come un singolo carattere, \ è il segnaposto per specificare che ciò che segue è una sequenza di escape. Se si vuole scrivere \, bisogna aggiungere \ per evitare che ciò che segue venga interpretato come una sequenza escape, stessa cosa per " ', che devono essere scritti così: " apri apici \" chiudi apici \" ", " apri apici \' chiudi apici \' " Ciao.
|
|
|
|
|
Logged
|
|
|
|
|
Capo d'Orlando
Offline
Sr. Member
Karma: 0
Posts: 305
Electronics & Web Dev, Unix User, Ω LEO, Rock/Deep Music, Tech/Science/Finance addicted, Ski/Snowboard and much more …
|
 |
« Reply #10 on: January 24, 2013, 01:10:04 pm » |
Ho risolto così: Per il primo: snprintf(rtty, 1000, "lat: %s - lon: %s - alt: %s | %d *C | %d %% | %d kPa \n", lat, lon, alt, temperaturartty, umiditartty, pressionertty); rtty_txstring(rtty); Per il secondo: snprintf(inviosms, 140, "lat: %s | lon: %s | alt: %s", lat, lon, alt); sms.SendSMS("3331234567", inviosms); Grazie a tutti ! 
|
|
|
|
|
Logged
|
|
|
|
|
|