1

I'm new to Raspberry PI and need help on this part as I need to write my temperature data to Windows Azure's Sqldatabase.

import smbus
import time
import datetime

#SMBus(0) - Raspberry Pi Model A
#SMBus(1) - Raspberry Pi Model B

bus = smbus.SMBus(1)

#I2C address of sensor
address = 0x48

def temperature():
rvalue0 = bus.read_word_data(address,0)
rvalue1 = (rvalue0 & 0xff00) >> 8
rvalue2 = rvalue0 & 0x00ff
rvalue = (((rvalue2 * 256) + rvalue1) >> 4 ) *.0625 #print rvalue1, rvalue2
return rvalue

print("Temperature Data Logger\n")

while True:

#Open Log File
f=open('tempdata.txt','a')
now = datetime.datetime.now()
timestamp = now.strftime("%Y/%m/%d %H:%M")
outvalue = temperature()
outstring = str(timestamp)+"  "+str(outvalue)+" C "+str(outvalue*1.8+32)+" F"+"\n" 
print outstring
f.write(outstring)
f.close()

#log temperature every 60 seconds
time.sleep(60)

I'm only able to write it out as text file but don't know how to write it to Windows Azure's Sqldatabase which I have created in management portal.

4
  • This answer suggests using pyodbc: How to connect python to SQL Azure?
    – scruss
    Jun 22, 2014 at 14:02
  • That link is for Windows and not from Raspberry PI Jun 24, 2014 at 6:18
  • On your raspberry, install freetds and pyodbc, then use connection string that @scruss mentioned. Jun 24, 2014 at 13:26
  • gurcanoztuk, could you guide me on what to type to install freetds and pyodbc cause I can't seems to find the package inside Raspberry Pi. Jun 26, 2014 at 12:54

1 Answer 1

2

What have you tried? What have you searched for? Both freetds and pyodbc show up in any apt-cache search I care to do.

This might get you started:

sudo apt-get install freetds-bin freetds-dev python-pymssql python-pyodbc python-sqlalchemy tdsodbc unixodbc-bin unixodbc-dev

There's some possibly helpful discussion here: Connect to MSSQL using FreeTDS / ODBC in Python.

Are you familiar enough with Python's database management? I'd strongly suggest you try setting up something which talks to a local SQLite database before jumping into the hairy weirdness that is Azure. Otherwise, this just seems like we're doing your homework for you …

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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