From wikipedia.org:
An SMS gateway allows a computer to send or receive Short Message Service (SMS) transmissions to or from a telecommunications network.
This is a fully functional HTTP-SMS-Gateway server that runs on any device supporting Firefox OS (FxOS).
#→ Why a FxOS based SMS gateway?
There are many ways to hack together a SMS gateway server…
A Raspberry Pi with a Adafruit FONA - Mini Cellular GSM Breakout Board connected.
A Raspberry Pi with a Nokia 3310 connected.
A Geeksphone Keon.
- I wanted to show that FxOS is more than a mobile phone OS
- A SMS gateway involves many parts of a mobile phone "dev board" ;)
- It's easy to implement
- I already knowed most of the things from my Firefox OS washing machine project ;)
- Firefox OS devices as general purpose dev boards
- It's just JavaScript
- Rapid prototyping
- Lot's of resources and frameworks available because of JavaScript
- Firefox OS: Dev board with WiFi, Touchscreen, Bluetooth, Cellular Connection, Hardware Buttons and much more for round about 50 Euro
- There are frameworks for Web Server, Simple Service Discovery, Physical Web, Web Bluetooth ... you name it
- The main network connection and SMS gateway logic requires 600 lines of code
- Firefox OS is based on three parts, Gonk, Gecko and Gaia
- Gonk contains the kernel, hardware abstraction layer and other low-level components
- Gecko is the application platform layer running all JavaScript and rendering stuff
- Gaia is the main thing that makes up Firefox OS
This gateway server replaces Gaia and with it's own code.
-
If the device get's power connection, it will instantly boot up
-
There's no way to shut it down (no one can by mistake shut it off)
-
The server will work with wifi or cellular connection
-
The connection has to be configured by putting a settings.json file in the root folder of the devices sd-card
-
If connection is established, it starts a HTTP server running the REST-ful API
-
On request, it sends a SMS to the given number and responds the status
- Parsing the cellular and wifi config
- Connect to cellular and wifi network
- Start a HTTP server
- Send SMS from web request
- Respond with the send status
This is how the settings file on the sd-card looks like:
{
"wifi": {
"enabled": true,
"network": "YOUR_SSID",
"password": "YOUR_WIFI_PASSWORD"
},
"cellular": {
"roaming": false,
"edgeOnly": false,
"pin": "0000"
}
}
Determine which sd-card contains the file:
var volumes = navigator.getDeviceStorages('sdcard');
volumes.forEach(volume => {
var request = volume.get('settings.json');
request.onsuccess = sdcard => {
// load settings
};
});
Internal storage may also be available as sdcard!
Load the settings from the file:
request.onsuccess = () => {
var reader = new FileReader();
reader.onload = e => {
var config = JSON.parse(e.target.result);
// do something with the config
};
reader.readAsText(request.result);
};
Enable a connection for every SIM card (there may be more than one)
[].forEach.call(navigator.mozMobileConnections, conn => {
conn.setPreferredNetworkType(config.cellular.edgeOnly ? 'gsm' : 'wcdma/gsm-auto');
conn.setRadioEnabled(true);
});
There's some more code necessary for handling error cases or SIM unlocking if it is secured by a PIN. You will find it in the repository on Github.
var n = navigator.mozWifiManager.getNetworks();
n.onsuccess = () => {
var wifi = n.result.filter(w => w.ssid === config.wifi.network)[0];
if (wifi.security.length > 0 && wifi.security[0] === 'WPA-PSK') {
wifi.keyManagement = 'WPA-PSK';
wifi.psk = config.wifi.password;
}
navigator.mozWifiManager.associate(wifi);
};
navigator.mozWifiManager.onconnectioninfoupdate = e => {
var httpServer = new HTTPServer(80);
httpServer.addEventListener('request', evt => {
evt.response.headers['Content-Type'] = 'application/json';
evt.response.send('{"message":"Hello World!"}');
});
console.log('http://' + e.ipAddress + ':80/');
};
The server implementation is based on https://hacks.mozilla.org/2015/02/embedding-an-http-web-server-in-firefox-os/
httpServer.addEventListener('request', evt => {
if (evt.request.path === '/send') {
var sms = navigator.mozMobileMessage.send(
request.params.number,
request.params.message
);
sms.onsuccess = () => {
response.send('{"message":"Message sent successfully"}');
};
sms.onerror = () => {
response.send('{"message":"Error: ' + sms.error + '"}');
};
}
});
You can find the source code for this gateway server on Github: https://github.com/SunboX/fxos-HTTP-SMS-Gateway
Most of the server's logic can be found inside the /apps/system/js
folder.
You should really try to hack on Firefox OS yourself
Not only like "hacking apps" or add-ons, but also hacking Firefox OS itself. It's open, free and easy to start building great things with it. There's even cheap hardware all around, with sensors, cameras, bluetooth, wifi, gps ... things you can't get this easy with your famous hacker board.
contact: [email protected]
twitter @sonnenkiste
github github.com/SunboX
linkedin linkedin.com/profile/view?id=226588234
g+ plus.google.com/116509237159086833815