Back to Smartcitizen.me

Storing data in mysql database


#1

I want to store my data from firmware directly in my mysql database (not via restful api). Dived into the code. It is poorly documented. What’s the best approach here? Anyone done this already?


#2

Hello Marc,

We are currently working on documenting properly our current backend to release it publicly.

The Smart Citizen Kit is publishing by default the data as a PUT Http request, the sensor data is encoded as JSON.

Here you can see how a kit’s request will look like.

curl -X PUT -H 'Host: data.smartcitizen.me' -H 'User-Agent: SmartCitizen' -H 'X-SmartCitizenMacADDR: 00:00:00:00:00:00' -H 'X-SmartCitizenVersion: 1.1-0.8.5-A' -H 'X-SmartCitizenData: [{"temp":"29090.6","hum":"6815.74","light":"30000","bat":"786","panel":"0","co":"112500","no2":"200000","noise":"2","nets":"10","timestamp":"2013-10-28 1:34:26"}]' data.smartcitizen.me/add

Data for the temperature, humidity and noise is sent it in raw and then calibrated in our platform.

Here are the different paths you can take in order to built your own backend.

  • Create a fork of the the Smart Citizen Kit firmware in order to send the data as your custom backend expect it.
  • Create your own custom backend. We can share all the different modules of our backend in order for you to receive data as on the curl example above, calibrate it and store it.
  • Keep using our backend but request our public API api.smartcitizen.me and then fill your local Mysql with it.

Please, let me know what option you will like the most and I can share with you our documentation.

Guillem.


#3

Hello Guillem.

Added some new code to firmware version 0.8.6. Compiling went ok. During upload something went wrong. (yes i selected the right board: lilypad usb). Now usb isn’t working anymore. Trying to burn new bootloader with arduino uno. Please specify pin layout of ICSP.

Marc


#4

Hi Marc! The ICSP pin layout is the same as in Arduino. Best. :slight_smile:


#5

The ICSP


#6

mdeheras,

Just to be sure:
pin 1 (MISO) is near Wifly card?
burning bootloader is done with 3,3 V not 5 V?

Marc


#7

What programmer do you use? Yes, is near Wifly card. VCC is 3.3v.


#8

mdeheras,

I tried using arduino uno as programmer. Having trouble burning the bootloader. Keep getting the famous error “avrdude: Yikes! Invalid device signature.”

The relevant part of the boards.txt file is:

LilyPadUSB.name=LilyPad Arduino USB
LilyPadUSB.upload.protocol=avr109
LilyPadUSB.upload.maximum_size=28672
LilyPadUSB.upload.speed=57600
LilyPadUSB.upload.disable_flushing=true
LilyPadUSB.bootloader.low_fuses=0xff
LilyPadUSB.bootloader.high_fuses=0xd8
LilyPadUSB.bootloader.extended_fuses=0xce
LilyPadUSB.bootloader.path=caterina-LilyPadUSB
LilyPadUSB.bootloader.file=Caterina-LilyPadUSB.hex
LilyPadUSB.bootloader.unlock_bits=0x3F
LilyPadUSB.bootloader.lock_bits=0x2F
LilyPadUSB.build.mcu=atmega32u4
LilyPadUSB.build.f_cpu=8000000L
LilyPadUSB.build.vid=0x1B4F
LilyPadUSB.build.pid=0x9208
LilyPadUSB.build.core=arduino
LilyPadUSB.build.variant=Leonardo

The relevant part of the programmers.txt file is:

arduinoisp.name=Arduino as ISP
arduinoisp.communication=serial
arduinoisp.protocol=stk500v1
arduinoisp.speed=19200

The relevant part of the avrdude.conf file is:

#------------------------------------------------------------

ATmega32u4

#------------------------------------------------------------

part
id = “m32u4”;
desc = “ATmega32U4”;
signature = 0x1e 0x95 0x87;
has_jtag = yes;

stk500_devcode = 0xB2;

avr910_devcode = 0x43;

Are these settings correct?

Anyone succeeded burning the bootloader?

Marc


#9

We program the boards from the Arduino IDE, and never given us problems, we use the AVRISP mkII programmer.


#10

mdeheras,

Tried using arduino uno as programmer for the board. It’s not working. Burning a bootloader onto another arduino uno works. Ordered the AVRISP mkII programmer. Keep you informed.

Marc


#11

Hi, I’ve tried to program with Arduino Duemilave and working properly, I send you a screenshot with the wiring.


#12

@marcvreeburg after making similar code changes to my kit I also lost the USB totally. I was able to revive the board by pressing the reset button twice in rapid succession. See http://arduino.cc/en/Guide/ArduinoLilyPadUSB .

Hopefully this helps.


#13

@marcvreeburg; Apparently we share the same ambition. Did you already made some progress? Or does anyone know about the documentation status.

I would like to send the information from the sck directly to a OGC SOS (http://www.opengeospatial.org/standards/sos/). In order to do this, I need to transform the PUT-request into a POST-request.

Like the following Python example:
webservice = httplib.HTTP(“XXX.XXX.XX.X:8080”)
webservice.putrequest(“POST”, “/SOS/json”)
webservice.putheader(“Host”, “XXX.XXX.XX.X:8080”)
webservice.putheader(“User-Agent”, “SCK post”)
webservice.putheader(“Content-type”, “application/json; charset=“UTF-8"”)
webservice.putheader(“Content-length”, “%d” % len(SoapMessage))
webservice.putheader(“SOAPAction”, “””")
webservice.endheaders()
webservice.send(SoapMessage)

Looking forward to hear any suggestions.