The community forums are in BETA and closed to the public.

Writing Array Data sent from Corona SDK via pubnub to MYSQL and mongodb

So, I'm writing a Mobile app using Corona SDK and it publishes event driven data via pubnub. I'd like to write this data to a web hosted database. Either MySQL or ultimately mongodb. For the time being I'm just using the event data for touch and move on the screen and just sending a phone#, elapsed times in 1/4th second increments and the x position on the viewable area of the mobile device. I'd be happy to share the entire Corona Project directory. I really have no idea what the best approach would be to get this data (from many current devices) into a database. Is there a simple way to have MySQL or Mongodb subscribe to the selected channel of the app or do I need an intermediary like node.js or php. If there are any examples or if someone has some example code it would be really helpful. In the meantime I'm posting this working Corona SDK source for anyone to use or play with. If anyone wants the full project directory I'll zip it up and email it. Its small. - Thanks for your consideration. Having an easy way to get real time data from a mobile app to a database would be a fantastic utility!!

display.setStatusBar( display.HiddenStatusBar )

local stopwatch = require "stopwatch"
local json = require("json")
require "pubnub"
require "PubnubUtil"

textout = PubnubUtil.textout
------------------VARIABLES-----------------------------------------------

-- Create a stop watch timer
local phone = 5551212
local timeKeep = stopwatch.new()
local user
local xPosition
local background = display.newImageRect( "bg.png", 480, 320 )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0


-- Create a stop watch timer
local timeKeep = stopwatch.new()

local posTime

-------------------Function Variables------------------------------------

local onTouch
local _W = display.contentWidth
local _H = display.contentHeight


local bg = display.newImage("bg.png")
bg.x = _W * 0.5; bg.y = _H * 0.5

--
-- INITIALIZE PUBNUB STATE
--

pubnub_obj = pubnub.new({
    publish_key   = "my pub key",
    subscribe_key = "my sub key",
    secret_key    = nil,
    ssl           = nil,
   -- origin        = "pubsub.pubnub.com"
})
------------------Functions-----------------------------------------------
-- 
-- CALL PUBLISH FUNCTION
--
--============================
function publish(channel, text)
    pubnub_obj:publish({
        channel = channel,
        message = text,
        callback = function(r) --textout(r) 
        end,
        error = function(r) textout(r) 
        end
    })
end
--=================================
function publish(channel, text)
    pubnub_obj:publish({
        channel = "z",
        message = text,
        callback = function(r) --textout(r) 
        end,
        error = function(r) textout(r) 
        end
    })
end


function onTouch(event) 
    --local posTime
    local my_channel = 'z'
    if "began" == event.phase then

        xPosition = event.x
        --print(xPosition)

    elseif event.phase == "moved" then
        xPosition = event.x 
        --print(xPosition)
    end 

    posTime = timeKeep:getElapsed()/250

    print(posTime)
    print(xPosition)
    publish(my_channel, {phone, posTime, xPosition})
end

background:addEventListener( "touch", onTouch)

Hi Guy!

Just noticed this super old topic here that was unanswered. Were you able to move forward and find a solution to your issue?

Well, I have decided that the best approach may be to use node.js and I'm thinking postgresql for the very high concurrency inserts and the required stability. It would be very very beneficial if you would be willing to show me how to take the data I am publishing from the Corona App above and insert it into PostgresSQL running on Heroku. I don't really know which modules would be best to accomplish that in node.js. I have progressed through javascript and working through jquery as I also have about 25 hours into node.js. All meshing together but any little help I can get on something so fundamental as simply inserting the simple array data published out of pubnub via node.js will accelerate my ability to complete the proof of concept, receiving funding and then hopefully get a whole bunch of devices sending data at high volume. I really appreciate your personal touch as well as the sheer creative and programing genius your product encompasses.


Comments to this discussion are now closed!