hello there, :)
i have a problem with hypnotoad when i use morbo it work fine but when i 
use hypnotoad i get this message
"Mojo::Reactor::Poll: Read failed: Can't locate object method "send" via 
package "Mojo::Transaction::HTTP" at hardware/graph_websocket.pl line 66."
any idea? 
thank for the help

#code...............................................
#!/usr/bin/env perl
# use Mojo::UserAgent;
use Mojolicious::Lite;
use JSON::XS;
use Time::HiRes qw/ sleep gettimeofday /;
use DateTime;
use DBI;

my $id       = 'TIEMPO REAL';
my $url      = 'ws://localhost:3000/bc';
my $limit    = 2000; 
my $interval = 0.05; # 50msec
send_graph_stat();

#------------------------------------------------------------
sub send_graph_stat {
    my $ua = Mojo::UserAgent->new;
    my $count = 0;
#------------------Create Table graph.db if not exists
my $dbh = DBI->connect("dbi:SQLite:hardware/sqlite/graph.db", "", "") or 
die "couldn’t connect to db".DBI->errstr;
my $stmt = "CREATE TABLE IF NOT EXISTS GRAPH (ID INTEGER PRIMARY KEY, 
DATOS_GRAPH INT)";
$dbh->do($stmt);
   
   #----------------------------------------------------------------
    $ua->websocket($url => sub {
  
        my ($ua, $tx) = @_;
        $tx->on(finish  => sub { print "WebSocket closed.\n" });
        $tx->on(message => sub {
            my ($tx, $msg) = @_;
            my $ref = JSON::XS->new->decode( $msg );
            if( $ref->{id} ne $id ) { # ignore msg from all nodes except 
itself
                return;
            }
            sleep $interval;
 #-read graph.db--------
my $stmt1 = qq(SELECT MAX(rowId),DATOS_GRAPH FROM graph;);
my $rv = $dbh->selectall_arrayref($stmt1) or die $DBI::errstr;
if( $rv < 0 ){ print $DBI::errstr; }
my ($datos_graph,$id_sql);
foreach my $row (@$rv) { ($id_sql, $datos_graph) = @$row; }
#----------------------
            # my $now = DateTime->now;  # can not measure less than 1 
second            
my $now = DateTime->now(time_zone=>"local");
            my $msg_ref = {
                type    => 'data',
                id      => $id,
                date    => $now->strftime('%Y-%m-%dT%H:%M:%S.%3NZ'),
                in_graph  => sprintf("%.2f",$datos_graph)                
            };

            $tx->send( JSON::XS->new->encode($msg_ref) );
            $count++;
            if( $count > $limit ) { 
                $tx->finish;
            }
        });

        # init message
        my $msg_ref = {
            type => 'hello',
            id   => $id
        };
        *$tx->send( JSON::XS->new->encode($msg_ref) );*
    });
    Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to