require "alone" require "json" class DataPostController < AlController FILENAME = "/var/log/logger/data-" def action_index data = AlForm.get_parameter(AlText.new("data")) log data data = JSON.parse( data ) now = Time.now filename = FILENAME + now.strftime("%Y%m%d") + ".csv" csv = now.strftime("%Y-%m-%d %H:%M:%S, ") + sprintf("%.2f, %.1f\r\n", data["pressure"].to_f, data["temperature"].to_f) open(filename, "a") {|file| file.write( csv ) } puts "OK" end end