Posted by & filed under Edison, IoT, Linux.

Continuing working on IoT stuff, I had the challenge to enable a 4G LTE cellular modem shield on the Edison board. The standard yocto image for Intel Edison does not have support for FTDI and PPP modules, so we need to recompile the kernel and enable those modules.

Custom image

The BSP user guide explains very well how to create a custom kernel for the Edison. The first thing we need to do is to perform the initial build (Page 7, Build an Intel® Edison Image using bitbake). This will take approximately 3-4 hours depends on your host machine.

After that, follow the steps on Page 14, Customizing the Linux* Kernel. To enable the FTDI module, once you run bitbake virtual/kernel -c menuconfig command, navigate through Device Drivers-> USB support -> USB Serial Converter support and enable USB FTDI Single Port Serial Driver as a module typing the letter M.

ftdi

After that, let’s enable the PPP module. Navigate through Device Drivers -> Network Device Support and enable all the options under PPP support using letter Y.

ppp

Run the bitbake edison-image command again and it should include the changes. Go ahead and run the script ../meta-intel-edison/utils/flash/postBuild.sh to create the toFlash folder with all the necessary files. In my case, I had to modify the postBuild.sh script and change the path correctly.

Now you will be able to flash the image into your Edison (http://www.intel.com/support/edison/sb/CS-035280.htm).

Initial setup

Once you finish flashing your custom image, we need to install a couple of packages.

First, run the command configure_edison –setup

Install FTDI and PPP packages:

# opkg install http://repo.opkg.net/edison/repo/edison/kernel-module-ftdi-sio_3.10.17-r0_edison.ipk

# opkg install http://repo.opkg.net/edison/repo/core2-32/ppp_2.4.6-r0_core2-32.ipk

After that, you should be able to see /dev/ttyUSB0.

Setting up PPP connections

# vi /etc/ppp/peers/simple

/dev/ttyUSB0

115200

connect “/usr/sbin/chat -v -f /etc/ppp/peers/simple-chat”

noauth

defaultroute

usepeerdns

local

debug

updetach

# vi /etc/ppp/peers/simple-chat

TIMEOUT 35

ECHO ON

ABORT ‘\nBUSY\r’

ABORT ‘\nERROR\r’

ABORT ‘\nNO ANSWER\r’

ABORT ‘\nNO CARRIER\r’

ABORT ‘\nNO DIALTONE\r’

ABORT ‘\nRINGING\r\n\r\nRINGING\r’

” \rATZ

OK AT#SIMDET=1

OK ‘ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0’

OK AT+CGDCONT=1,”IP”,”simple”

OK ATD*99***1#

CONNECT ”

Once you create those two files, you can run the command

# pppd call simple

Note that this configuration is based on simple mobile carrier. See your documentation for other carriers.

Posted by & filed under c++, Snippets.

Recursive function that receives an integer array and its size. Determines if the elements in the array are increasing.

Example:

TRUE: {1,3,5,6,8}
FALSE: {4,3,5,6,7,3}

bool isIncreasing(int arr[], int n){     
    
    if(n==0)
      return true;
    
    if(arr[n] > arr[n-1])
      return isIncreasing(arr,n-1);
    else
      return false;    
}

Posted by & filed under MongoDB, PHP, Snippets.

Document:

  "_id": ObjectId("502aa888f50138d88d0002f7"),
  "contestname": "HEB ",
  "date": ISODate("2012-08-14T19:37:57.788Z"),
  "description": "java programming contest",
  "expdate": ISODate("2012-08-31T05:00:00.0Z"),
  "maxnumteams": NumberInt(5),
  "numteams": NumberInt(3),
  "teams": [
    {
      "teamname": "Superstars",
      "userid1": "50247314f501399b020019bc",
      "userid2": "50293cf9f50139946400001c",
      "userid3": "50293cdff509984464000018"
    },
    {
      "teamname": "faculty",
      "userid1": "50247314f501399b020019bc",
      "userid2": "502a9fe2f50199196500461b",
      "userid3": "50293cf9f50199446400001c"
    }
  ],
  "term": "Fall 2012"
}
public function deleteTeam($id,$teamname) {
	$criteria = array('_id' => new \MongoId($id));	
	$team = array("teamname" => $teamname);		
	$update = array('$pull' => array('teams' => $team),
			'$inc' => array('numteams' => -1));
				
	return $this->collection->update($criteria, $update, array('safe' => TRUE));
		
	}

Posted by & filed under Javascript, PHP, Snippets.

Script.php

public function delete(){	
		 
	if($this->model->deleteUser($_POST['delete']))
		$ajax = array('success' => 1,'message' => 'Successfully Deleted');		
	else
		$ajax = array('success' => 0,'message' => 'User Not Found');			
	
	header('Content-type: application/json');
	die(json_encode($ajax));

	
}

script.js

$(document).ready(function() {
	
	$('.delete').click(function() {
		var row = $(this).parent().parent();
			
		if (confirm('Are You Sure?','')) {
			jQuery.post("/admin/users/delete/", { "delete": row.attr('id') },
				function(data) {
					if (data.success == 1) {						
						row.children().css("background", "red");
						row.fadeOut('750', function() {row.remove()});
					} else {						
						 alert(data.message); 
						   }
				});
		}
		return false;
	});
	
});

Posted by & filed under MongoDB, PHP, Snippets.


$team = array(	'teamname' => $_POST['tname'],
		'userid1' => $_POST['userid1'],
		'userid2' => $_POST['userid2'],
		'userid3' => $_POST['userid3']					
	      );

$contestid = $_POST['id'];

$this->collection->update(array('_id' =>new \MongoId($contestid)),
				array('$push' => array('teams' => $team),
						'$inc' => array('numteams' => 1))
                         );