Commit e010b885 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+33 −0
Changes for MakingThingsTalk-all-examples/AppA/midi/midi.pde: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
     MIDI
    Language: Wiring/Arduino
     
    plays MIDI notes from 30 to 90 (F#-0 to F#-5)
*/

char note = 0;      // The MIDI note value to be played

void setup() {
 // Set MIDI baud rate:
 Serial.begin(31250);
}

void loop() {
 // play notes from F#-0 (30) to F#-5 (90):
 for (note = 0; note < 127; note ++) {
  //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
  noteOn(0x90, note, 0x70);
  delay(10);
  //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
  noteOn(0x90, note, 0x00);  
  delay(10);
 }
}

// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(char cmd, char data1, char data2) {
 Serial.print(cmd, BYTE);
 Serial.print(data1, BYTE);
 Serial.print(data2, BYTE);
}
+34 −0
Changes for MakingThingsTalk-all-examples/AppA/phone_finder.php: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
/*
    Phone Finder
    Language: PHP
    
    Identifies the user agent and IP address and sends an email
    notification. Runs on mobile phones.

*/
 $userAgent = getenv('HTTP_USER_AGENT');
 $ipAddress = getenv('REMOTE_ADDR');
 sendMessage('you@example.com', 'user agent', 
   "$userAgent $ipAddress");
 
     echo <<<END
<html>
<head></head> 

<body>
    <h2>Hi There</h2>
        Your IP: $ipAddress<br>
        Your browser: $userAgent<br>
        Thanks!
</body>
</html>
END;

 end;

function sendMessage($to, $subject, $message) {
    $from = "phone@example.com";
    mail($to, $subject, $message, "From: $from");
}
 ?>
+97 −0
Changes for MakingThingsTalk-all-examples/AppA/serial_server/serial_server.pde: 97 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 Serial Server
 language: processing
 
 This program makes a connection between a serial port
 and a network socket.
 
*/

import processing.serial.*;
import processing.net.*;

int socketNumber = 9001; // the port the server listens on
Server myServer;         // the server
Client thisClient;       // the reference to the client that logs
char terminationString = '\0'; // zero terminator byte

Serial myPort;            // the serial port you're using
String portnum;           // name of the serial port
String outString = "";    // the string being sent out the serial port
String inString = "";     // the string coming in from the serial port
String socketString = ""; // string of bytes in from the socket
int receivedLines = 0;    // how many serial lines have been received 
int bufferedLines = 5;    // number of incoming lines to keep

void setup() {
 size(400, 300);       // window size

 // create a font with the a font available to the system:
 PFont myFont = createFont(PFont.list()[2], 14);
 textFont(myFont);

 // list all the serial ports:
 println(Serial.list());

 // based on the list of serial ports printed from the 
 //previous command, change the 0 to your port's number:
 portnum = Serial.list()[0];
 // initialize the serial port:
 myPort = new Serial(this, portnum, 9600);
 // buffer until a newLine:
 myPort.bufferUntil('\n');
 // start the server:
 myServer = new Server(this, socketNumber); // Starts a server

}

void draw() {
 // clear the screen:
 background(0); 
 // print the name of the serial port:
 text("Serial port: " + portnum, 10, 20);
 // Print out what you get:
 text("From serial port:\n" + inString, 10, 80);
 text("From socket:\n" + socketString, 200, 80);

 // if the client is not null, and says something, display 
 // what it said:
 if (thisClient !=null) {
  // print out the current client:
  text("Active client: " + thisClient.ip(), 10, 60);
  // read what the client said:
  String whatClientSaid = thisClient.readString();
  if (whatClientSaid != null) {
   // save what it said to print to the screen:
   socketString = whatClientSaid;
   // send what it said out the serial port:
   myPort.write(socketString);
  }
 } 
}

// this method runs when bytes show up in the serial port:
void serialEvent(Serial myPort) {
 // read the String from the serial port:
 String whatSerialSaid = myPort.readStringUntil('\n');
 if (whatSerialSaid != null) {
  // save what it said to print to the screen:
  inString = whatSerialSaid;
  // if there is a netClient, send the serial stuff to them:
  if (thisClient != null) {
   // put a zero byte before and after everything you send to Flash:
   thisClient.write(terminationString);
   // send the actual text string:
   thisClient.write(inString);
   // add the end zero byte:
   thisClient.write(terminationString);
  }
 }
} 

void serverEvent(Server myServer, Client someClient) {
 if (thisClient == null) {
  // don't accept the client if we already have one:
  thisClient = someClient;
 }
}
+53 −0
Changes for MakingThingsTalk-all-examples/AppA/sms_messenger.php: 53 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
/*
    SMS messenger
    Language: PHP
    
    Sends SMS messages

*/
    $phoneNumber = $_GET["phoneNumber"];    // Get the phone number 
    $carrier   = $_GET["carrier"];          // Get the carrier 
    $message   = $_GET["message"];          // Get the message 
    $recipient = $phoneNumber."@".$carrier; // Compose the recipient
    
    // If there's a phone number in the form, you can send:
    if ($phoneNumber != null) {                
        // send the message:
        $from = "you@yourmailhost.com";
        mail($recipient, "Mail message", $message, $from);
     }
     
     // Finally, print the browser form:
     echo <<<END
<html>
<head></head> 

<body>
    <h2>SMS Messenger</h2>
         <form name="txter" lookupMethod="post" action="sms.php">
         
      Phone number: <input type="text" name="phoneNumber"
        size='15' maxlength='15'><br>
        Message: <input type="text" name="message" size='30' 
           maxlength='128'><br>
          Carrier:     $to<br>

          <select name="carrier">
                <option value="teleflip.com">Teleflip</option>              
                <option value="tmomail.net">T-Mobile</option>
                <option value="messaging.sprintpcs.com">Sprint</option>
                <option value="txt.att.net">AT&T</option>
                <option value="vtext.com">Verizon</option>
                <option value="messaging.nextel.com">Nextel</option>
            </select>
  
        <input type="submit" name="Submit" value="submit">
      
      </form>
</body>
</html>

END;

?>
+45 −0
Changes for MakingThingsTalk-all-examples/AppA/socket_test.as: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
    Socket Test
    Language: ActionScript 2.0
    
    Exchanges strings through an XMLSocket
*/

var i = 0;        // counter for the number of clicks

createSocket();

function createSocket() {
    socket = new XMLSocket();
    // 127.0.0.1 is the same as "localhost" 
    // i.e. an alias to your local machine
    socket.connect("127.0.0.1",9001);
    // define the functions that get called when these events happen:
    socket.onConnect = success;
    socket.onClose = closed;
    socket.onData = newData;
}

// When you click on the screen, Flash sends a click out 
// the server port:
function onMouseUp() {
    trace("click");
    socket.send("click ");
    socket.send(i);
    i++;
}

function success() {
    trace("socket opened");
    socket.send("F\n");// tell proxy it is talking to flash
}

function closed() {
    trace("socket closed");
    socket.send("Q\n");// tell Proxy Flash is closing socket
}

function newData(inString) {
    trace(inString); // trace the packet of data to the Flash 
                     // output screen
}
 No newline at end of file
Loading