#!/bin/bash -e
-HOSTNAME="$1"
+HOSTNAME="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
if [ "$HOSTNAME" == "" ]; then
echo "Usage: $0 <hostname>"
exit 1
fi
-if [ $(echo "$HOSTNAME" | tr '[:upper:]' '[:lower:]') == "localhost" ]; then
+if [ "$HOSTNAME" == "localhost" ]; then
echo "Cannot set hostname to 'localhost'"
exit 1
fi
+if [ "$HOSTNAME" =~ ^.*\.local$ ]; then
+ echo "Hostname cannot end with '.local'"
+ exit 1
+fi
+
if [[ ! "$HOSTNAME" =~ ^[a-zA-Z0-9-]{1,63}$ ]]; then
echo "Invalid hostname '$HOSTNAME'"
exit 1
sed -i "s/^127.0.1.1\([[:space:]]*\).*$/127.0.1.1\1$HOSTNAME/" /etc/hosts
echo "$HOSTNAME" > /etc/hostname
-/etc/init.d/hostname.sh
-sync
--- /dev/null
+#!/bin/bash
+
+USER=bbmc
+HOST=bbctrl.local
+
+if [ $# -eq 1 ]; then
+ if [[ "$1" = *@ ]]; then
+ LOGIN="$1"
+ else
+ LOGIN=$USER@"$1"
+ fi
+else
+ LOGIN=$USER@$HOST
+fi
+
+ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$LOGIN"
message(:show.sync="firmwareUpgrading")
h3(slot="header") Firmware upgrading
- p(slot="body") Please wait. . .
+ p(slot="body") Please wait...
message(:show.sync="hostnameSet")
h3(slot="header") Hostname Set
- p(slot="body")
- | Hostname was successfuly set to {{hostname}}.
- | Poweroff and restart the controller for this change to take effect.
+ div(slot="body")
+ p Hostname was successfuly set to <strong>{{hostname}}</strong>.
+ p Rebooting. Please wait...
+ p Redirecting in {{redirectTimeout}} seconds.
+ div(slot="footer")
message(:show.sync="passwordSet")
h3(slot="header") Password Set
hostnameSet: false,
usernameSet: false,
passwordSet: false,
+ redirectTimeout: 0,
latest: '',
hostname: '',
username: '',
api.get('hostname').done(function (hostname) {
this.hostname = hostname;
}.bind(this));
+
api.get('remote/username').done(function (username) {
this.username = username;
}.bind(this));
methods: {
+ redirect: function (hostname) {
+ if (0 < this.redirectTimeout) {
+ this.redirectTimeout -= 1;
+ setTimeout(function () {this.redirect(hostname)}.bind(this), 1000);
+
+ } else {
+ location.hostname = hostname;
+ this.hostnameSet = false;
+ }
+ },
+
+
set_hostname: function () {
api.put('hostname', {hostname: this.hostname}).done(function () {
+ this.redirectTimeout = 45;
this.hostnameSet = true;
+
+ api.put('reboot').always(function () {
+ var hostname = this.hostname;
+ if (String(location.hostname).endsWith('.local'))
+ hostname += '.local';
+ this.redirect(hostname);
+ }.bind(this));
+
}.bind(this)).fail(function (error) {
alert('Set hostname failed: ' + JSON.stringify(error));
})
};
-// ADC
+// ADC channels
enum {
CS1_ADC, // Motor current
CS2_ADC, // Vdd current
#define VOLTAGE_REF_R2 1000
#define CURRENT_REF_MUL 1970
+ // Addresses 0x60 to 0x67
#define I2C_ADDR 0x60
#define I2C_MASK 0b00000111
if (status & I2C_DATA_INT_BM) {
if (status & I2C_READ_BM) {
- // send response
+ // Send response
if (byte < 2) {
switch (byte++) {
case 0: TWSD = reg; break;
} else if (status & I2C_ADDRESS_STOP_INT_BM) {
if (status & I2C_ADDRESS_MATCH_BM) {
- // read address
+ // Read address
uint8_t addr = (TWSD >> 1) & I2C_MASK;
if (addr < NUM_REGS) {
return s
+class RebootHandler(bbctrl.APIHandler):
+ def put_ok(self): subprocess.Popen('reboot')
+
+
class HostnameHandler(bbctrl.APIHandler):
def get(self):
p = subprocess.Popen(['hostname'], stdout = subprocess.PIPE)
def put(self):
if 'hostname' in self.json:
if subprocess.call(['/usr/local/bin/sethostname',
- self.json['hostname']]) == 0:
+ self.json['hostname'].strip()]) == 0:
self.write_json('ok')
return
handlers = [
(r'/websocket', WSConnection),
+ (r'/api/reboot', RebootHandler),
(r'/api/hostname', HostnameHandler),
(r'/api/remote/username', UsernameHandler),
(r'/api/remote/password', PasswordHandler),