Skip to content

Instantly share code, notes, and snippets.

@aaronsherwood
Last active December 14, 2015 18:39
Show Gist options
  • Save aaronsherwood/5131236 to your computer and use it in GitHub Desktop.
Save aaronsherwood/5131236 to your computer and use it in GitHub Desktop.
code for moshi moshi
#include <Ethernet.h>
#include <SPI.h>
#include <Audio.h>
#include <SD.h>
const int inputPin = 24;
char server[] = "asterisk.itp-redial.com";
String location = "/~ags419/sinatra/wifeSignal/getout HTTP/1.0";
bool vol;
// if need to change the MAC address (Very Rare)
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?
String prevPagVal;
int volume = 1024;
void setup(){
Serial.begin(9600);
prevPagVal="45";
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println(" failed!");
return;
}
Serial.println(" done.");
Ethernet.begin(mac);
pinMode(inputPin, INPUT);
vol=false;
}
void loop(){
String pageValue = connectAndRead(); //connect to the server and read the output
vol=false;
volume = 1024;
if (pageValue!=prevPagVal){
Serial.println(pageValue); //print out what's on the web page
File myFile = SD.open("bowed.wav");
if (!myFile) {
Serial.println("error opening bowed.wav");
while (true);
}
const int S=1024; // Number of samples to read in block
short buffer[S];
SPI.setClockDivider(4);
Audio.begin(88200, 0);
while (myFile.available()) {
// read from the file into buffer
if (digitalRead(inputPin)==1){
vol=true;
}
if (vol && volume>0) {
volume-=32;
}
myFile.read(buffer, sizeof(buffer));
// Prepare samples
Audio.prepare(buffer, S, volume);
// Feed samples to audio
Audio.write(buffer, S);
}
myFile.close();
}
prevPagVal=pageValue;
delay(10000);
}
String connectAndRead(){
//connect to the server
//port 80 is typical of a www page
if (client.connect(server, 80)) {
client.print("GET ");
client.println(location);
client.println();
//Connected - Read the page
return readPage(); //go and read the output
}
else{
return "connection failed";
}
}
String readPage(){
//read the page, and capture & return everything between '<' and '>'
stringPos = 0;
memset( &inString, 0, 32 ); //clear inString memory
while(true){
if (client.available()) {
char c = client.read();
if (c == '<' ) { //'<' is our begining character
startRead = true; //Ready to start reading the part
}
else if(startRead){
if(c != '>'){ //'>' is our ending character
inString[stringPos] = c;
stringPos ++;
}
else{
//got what we need here! We can disconnect now
startRead = false;
client.stop();
client.flush();
return inString;
}
}
}
}
}
;x's indicate a phone number. the first one would be mine, the second one kiori's (with a 1 in front)
exten => ans,1,Set(CALLERID(num)=xxxxxxxxxx)
exten => ans,n,System(/home/ags419/asterisk_agi/postRequestWifeSignal.rb 1)
exten => ans,n,Dial(SIP/flowroute/1xxxxxxxxxx,30,r)
#!/usr/bin/ruby
require 'net/http'
require 'uri'
num = ARGV[0]
postData = Net::HTTP.post_form(URI.parse('http://asterisk.itp-redial.com/~ags419/sinatra/wifeSignal/putin'), {'number'=>num})
puts postData.body
require 'sinatra'
require 'rubygems'
require 'dm-core'
require 'fileutils'
require 'net/smtp'
DataMapper::setup(:default, {:adapter => 'yaml', :path => 'db'})
class Phonecall
include DataMapper::Resource
property :id, Serial
property :number, Integer
end
DataMapper.finalize
get '/getout' do
@number = Phonecall.last.number
@id= Phonecall.last.id
"<#{@id}>"
end
post '/putin' do
send_email "0101@hotmail.com", :body => "Trying to call you now, yo!"
call = Phonecall.new
call.number = params[:number]
call.save
"did it"
end
def send_email(to,opts={})
opts[:server] ||= 'localhost'
opts[:from] ||= '0101@gmail.com'
opts[:from_alias] ||= 'Aaron'
opts[:subject] ||= "Moshi Moshi"
opts[:body] ||= "Trying to call you now, yo!"
msg = <<END_OF_MESSAGE
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <#{to}>
Subject: #{opts[:subject]}
#{opts[:body]}
END_OF_MESSAGE
Net::SMTP.start(opts[:server]) do |smtp|
smtp.send_message msg, opts[:from], to
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment