ATmega32U4 code:

#include <Mailbox.h>
void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  // Initialize Bridge and Mailbox
  Bridge.begin();
  Mailbox.begin();
  digitalWrite(13, HIGH);
  // Initialize Serial
  Serial.begin(9600);
  // Wait until a Serial Monitor is connected.
  while (!Serial);
  Serial.println("Mailbox Read Message\n");
  Serial.println("The Mailbox is checked every 10 seconds. The incoming messages will be shown below.\n");
}
void loop() {
  String message;
  // if there is a message in the Mailbox
  if (Mailbox.messageAvailable())
  {
    // read all the messages present in the queue
    while (Mailbox.messageAvailable())
    {
      Mailbox.readMessage(message);
      Serial.println(message);
    }
    Serial.println("Waiting 10 seconds before checking the Mailbox again");
  }
  // wait 10 seconds
  delay(10000);
}

AR9331 code:

opkg update
opkg install php5-cli php5-mod-sockets php5-mod-json
nano mailbox.php

<?php
require("/usr/lib/php/bridge/bridgeclient.class.php");
$client = new bridgeclient();
print("Sending mailbox message 'Hello world from PHP!'\n");
$client->mailbox("Hello world from PHP!");
?>
/usr/bin/php-cli  mailbox.php
Mailbox Read Message
The Mailbox is checked every 10 seconds. The incoming messages will be shown below.
Hello world from PHP!
Waiting 10 seconds before checking the Mailbox again

Write comment (0 Comments)

wget -O gcc-mips_4.6.3-1_ar71xx.ipk https://www.dropbox.com/s/jjw92p0qcksqebg/gcc-mips_4.6.3-1_ar71xx.ipk?dl=0 --no-check-certificate
wget -O libmpc_1.0.2-1_ar71xx.ipk https://www.dropbox.com/s/65tqv413wq0pstk/libmpc_1.0.2-1_ar71xx.ipk?dl=0 --no-check-certificate
wget -O libmpfr_3.1.2-1_ar71xx.ipk https://www.dropbox.com/s/ys2c3zodkdz26hx/libmpfr_3.1.2-1_ar71xx.ipk?dl=0 --no-check-certificate

opkg update
opkg install libmpfr_3.1.2-1_ar71xx.ipk
opkg install libmpc_1.0.2-1_ar71xx.ipk
opkg install gcc-mips_4.6.3-1_ar71xx.ipk

Write comment (1 Comment)

Connect ethernet cable between Router and Yun.

IDE upload Files-Examples->Bridge->YunSerialTerminal

at Terminal typing ifconfig

eth1      Link encap:Ethernet  HWaddr 90:A2:DA:F8:06:76
          inet addr:192.168.0.102  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:227753 errors:0 dropped:106274 overruns:0 frame:0
          TX packets:13416 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:56525322 (53.9 MiB)  TX bytes:1117732 (1.0 MiB)
          Interrupt:4
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:102 errors:0 dropped:0 overruns:0 frame:0
          TX packets:102 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:9854 (9.6 KiB)  TX bytes:9854 (9.6 KiB)
wlan0     Link encap:Ethernet  HWaddr 90:A2:DA:F0:06:76
          inet addr:192.168.240.1  Bcast:192.168.240.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:3645 (3.5 KiB)

Ethernet ip address:192.168.0.102

Wifi ip address:192.168.240.1

Write comment (0 Comments)

Set up Sqlite3 sensor.db

Native GCC & C and Sqlite3

nano /mnt/sda1/opendb.c
#include <stdio.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[])
{
   sqlite3 *db;
   sqlite3_stmt    *res;
   int rc;
   const char      *tail;
   int i;
   clock_t tic = clock();
   for(i = 0; i < 1000; i++) {
   rc = sqlite3_open("/root/sensor.db", &db);
   if( rc ){
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      exit(0);
   }else{
//      fprintf(stderr, "Opened database successfully\n");
   }
   rc = sqlite3_prepare_v2(db,"select temperature from sensor_data limit 1", 1000, &res, &tail);
   while (sqlite3_step(res) == SQLITE_ROW) {
//      printf("%s\n", sqlite3_column_text(res, 0));
   }
   sqlite3_finalize(res);
   sqlite3_close(db);
   }
   clock_t toc = clock();
   printf("Elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
   return 0;
}
cd /mnt/sda1
gcc -o opendb opendb.c -lsqlite3 -ldl -lpthread
./opendb
Elapsed: 3.590000 seconds



Speed is 3.59 ms

Write comment (0 Comments)