Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have referred the code from this link:http://www.daviom.com/tutorial/tutorial-store-arduino-data-with-raspberry-pi-to-mysql/ The arduino code is working correctly however the python code executes by giving the following output but does not store value in the database , even the tx light on the arduino blinks while the python code is executing but the values are not getting stored in the database

enter image description here

pls someone help me out as i am new to python

the output after uncommenting print statement in the python code enter image description here #print("value received:"+string+ " interpreted as: project Id = "+projectId+" and value = "+value) is not displaying any output the values from the arduino are inconsistent and the second print statement enter image description here enter image description here enter image description here

share|improve this question
    
How do you know they are not stored ?. The output you get seems the normal one after finishing the 50-cycles loop of the script. –  joaquin Jan 4 at 16:08
    
i checked the database but no values where stored in it –  user2218550 Jan 5 at 4:25
    
Did you check the loop runs ? (uncomment prints in the loop to check what the program is writing). –  joaquin Jan 5 at 6:42
    
i have un commented the loop the print(ardString) statement is outputing value coming form the arduino , but the string is inconsistent sometimes it displays as : x-50 and sometimes as x50 the second print statement "print("value received:"+string+ " interpreted as: project Id = "+projectId+" and value = "+value)" is not displaying any output i have attached the screenshot of the output after uncommenting print statement as you said . –  user2218550 Jan 5 at 7:50
    
check all prints: be sure you enter the if len(valueMatrix)> 1 which is neccesary to insert data on the dbase. If ardString is just what you report then it would not comply with the if because valueMatrix would be equal to 1. Another question: where x in x50 comes from ? On the arduino code you should have Serial.println("xyz123 " + tempAsString);. This should return something like "xyz123 50" in ardString . Did you wrote exactly this ? Did you noticed the space after 123 ? –  joaquin Jan 5 at 8:07
show 5 more comments

1 Answer

up vote 0 down vote accepted

Your arduino code

Serial.println("xyz123 " + tempAsString);

sends

"xyz123 value"     ("value" is any float value)

to your rasbperry and this string is stored in ardString.
If instead of the above you wrote:

Serial.println("xyz123" + tempAsString);

then

ardString  ->  "xyz123value"

and

valueMatrix = ardString.split(' ')  -> ["xyz123value"]

Thus, len(valueMatrix) is equal to 1 so that nothing is writen on the database.


Relative to the next error you got in the print when you corrected the arduino code, modify the print statement to (change string to ardString):

print("value received:" + ardString + " interpreted as: project Id = " + projectId + " and value = " + value)
share|improve this answer
    
thanks bro at last i had to only delete the foreign key from the code and thats it it worked ,anyways thanks for all your guidance it helped we learn what the code does –  user2218550 Jan 5 at 9:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.