News:

The Latest electronic and computer Tips that work!

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - branx86

#121
Copied from:  http://randomnerdtutorials.com/reprogram-sonoff-smart-switch-with-web-server/

Browse our projects by category

ESP8266
Arduino
Raspberry Pi
Home Automation
Sensor/Modules Guides

Make Arduino into FTDI programmer = Pin: GND + RST then connect the 3.3V, RX, TX, GND



Reprogram Sonoff Smart Switch with Web Server
25 Shares
In this post, you're going to learn how to flash custom firmware in the Sonoff device, so that you can control it with your own web server. I recommend that you read my previous post to get familiar with the Sonoff.

If you don't have a Sonoff yet, you can get one for $5 on eBay: http://ebay.to/2eNzHf2.

First, watch the step by step video tutorial below


Safety warning
Make sure you disconnect your Sonoff from mains voltage. Then, open the box enclosure.

warning-m

Sonoff pinout
RELATED CONTENT: Like ESP8266? Check out Home Automation Using ESP8266
The Sonoff is meant to be hacked, and you can see clearly that these connections were left out, so that you can solder some pins and upload a custom firmware. That's the pinout.
   


I've soldered 4 header pins, so that I can easily connect and disconnect wire cables to my Sonoff device.



Preparing your 3.3V FTDI module
You need an FTDI module to upload a new firmware to your Sonoff. Use the schematics provided as a reference.



DOWNLOAD FREE PDF: Getting Started with ESPlorer IDE and ESP8266
Warning: uploading a custom firmware is irreversible and you'll no longer be able to use the app eWeLink.

I've added a toggle switch in the power line, so that I can easily turn the Sonoff on and off to flash a new firmware without having to unplug the FTDI module.

I used hot glue to glue the ends of the wires together. This prevents you to make wrong connections between the FTDI and the Sonoff in the future.



Boot your Sonoff in Flashing Mode
To flash a new firmware to your Sonoff, you have to boot your Sonoff in flashing mode. Follow this 4 step process:

1) Connect your 3.3V FTDI programmer to your computer

2) Hold down the Sonoff button



3) Toggle the switch to apply power to the Sonoff circuit



4) Then, you can release the Sonoff button

Now, your Sonoff should be in flashing mode and you can upload a new firmware.

Opening the Arduino IDE
You should have the ESP8266 add-on installed in the Arduino IDE – If you don't have the add-on installed, first follow this tutorial on How to Install the ESP8266 Board in Arduino IDE.

You can upload the full sketch to your Sonoff (replace with your SSID and password):

/*********
  Rui Santos
  Complete project details at http://randomnerdtutorials.com 
*********/

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

MDNSResponder mdns;

// Replace with your network credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

ESP8266WebServer server(80);

String webPage = "";

int gpio13Led = 13;
int gpio12Relay = 12;

void setup(void){
  webPage += "<h1>SONOFF Web Server</h1><p><a href=\"on\"><button>ON</button></a>&nbsp;<a href=\"off\"><button>OFF</button></a></p>"; 
  // preparing GPIOs
  pinMode(gpio13Led, OUTPUT);
  digitalWrite(gpio13Led, HIGH);
 
  pinMode(gpio12Relay, OUTPUT);
  digitalWrite(gpio12Relay, HIGH);

  Serial.begin(115200);
  delay(5000);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
 
  server.on("/", [](){
    server.send(200, "text/html", webPage);
  });
  server.on("/on", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio13Led, LOW);
    digitalWrite(gpio12Relay, HIGH);
    delay(1000);
  });
  server.on("/off", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio13Led, HIGH);
    digitalWrite(gpio12Relay, LOW);
    delay(1000);
  });
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}



Preparing your Arduino IDE
Having your Sonoff device still in flashing mode.

1. Select your FTDI port number under the Tools> Port > COM14 (in my case)
2. Choose your ESP8266 board from Tools> Board > Generic ESP8266 Module
3. Press the Upload button


Wait a few seconds while the code is uploading. You should see a message saying "Done Uploading".

Troubleshooting
If you try to upload the sketch and it prompts the following error message:

warning: espcomm_sync failed
error: espcomm_open failed
Your Sonoff is not in flashing mode and you have to repeat the process described in section "Boot your Sonoff in flashing mode" described earlier in this guide.

Final circuit
After uploading the code, re-assemble your Sonoff. Be very careful with the mains voltage connections.

It's the exact same procedure as shown in the introductory guide.



ESP8266 IP Address
Open the Arduino serial monitor at a baud rate of 115200. Connect GPIO 0 of your ESP8266 to VCC and reset your board.

After a few seconds your IP address should appear. In my case it's 192.168.1.70.


Demonstration
For the final demonstration open any browser from a device that is connected to the same router that your Sonoff is. Then type the IP address and click Enter!



Now when you press the buttons in your web server you can control the Sonoff switch and any device that is connected to it.

Sonoff tutorials list:

Sonoff – $5 WiFi Wireless Smart Switch Introduction
How to Flash a Custom Firmware to Sonoff
Wrapping up
That's it for now, I hope you had fun learning about the Sonoff device. Make sure you subscribe to my blog, because I'll be posting more tutorials about the Sonoff.

Do you have any questions? Leave a comment down below!

Thanks for reading,

Rui























#122
US AC power circuit wiring color codes.

Function   label   Color, common   Color, alternative
Protective ground   PG   bare, green, or green-yellow   green
Neutral                   N               white                           grey
Line, single phase   L   black or red (2nd hot)   
Line, 3-phase   L1   black   brown
Line, 3-phase   L2   red   orange
Line, 3-phase   L3   blue   yellow


       
#123
Windows Fixes / Stop Win10 From Changing Settings
June 29, 2017, 08:35:16 AM
This is to stop Win10 from resetting  setting.   
#124
General Discussion / Syrup Conversions
June 29, 2017, 08:29:04 AM
Servings per box of soda 2.5 Gallons
5-1 dilution
7oz. = 301 servings
10oz. = 211 servings
12oz. = 176 servings
16oz. = 131 servings

20lbs CO2=90gallons
10lbs CO2=45gallons
5lbs CO2=22.5gallons

5parts syrup  to 1 water ratio
25 ounces water add 5 ounce syrup
Divide cup size by 6 for the number of ounces of syrup used per cup.
10oz. Cup 10/6= 1.7oz syrup to mix in water
12oz. Cup 12/6= 2oz. Syrup to mix in water
16oz. Cup 16/6= 2.7oz. Syrup to mix in water
20oz. Cup 20/6= 3.3oz. Syrup to mix in water

Start water ml / 6 = how much syrup
Start water ml - how much syrup = water to mix

For 20oz.
529ml or 20oz./6= 99ml or 3.3oz.syrup
529ml or 20oz. - 99ml or 3.3oz. = (493ml or 16oz.water)
715ml ,2.9cups water 143ml, 4.8oz syrup = perfect soda

Divide oz by oz size = how many cans or bottles


#125
Solar Power / Li-ion 3s1p Battery with BMS
June 07, 2017, 02:07:20 PM

#126
From:  http://geek.adachsoft.com/home/article/id/17/n/Raspberry-PI-with-DS18b20-web-server-PHP-Remote-temperature-measurement/refid/gp

How to make remote temperature measurement using Raspberry PI, DS18B20, PHP and PostgreSQL. This projection will show you how to easily make a temperature logger using the above technology. The entire temperature logger will be made using the PostgreSQL database. I will also show the example of a working online temperature logger on my website.
Step 1: Components

Raspberry PI
DS18b20
Some wires
Step 2: Requirements

In this project we will need installed:
Apache2
PHP
PHP PDO
PHP PostgreSQL
Install the apache2 package by typing the following command in to the Terminal:

   sudo apt-get update
   sudo apt-get install apache2
Then we install PHP.

   sudo apt-get install php5 libapache2-mod-php5
Install the PostgreSQL.

   sudo apt-get install php5-pgsql
Step 3: Connection of the temperature sensor

The DS18B20 sensors can be connected in parallel. The resistor 4.7k is used as a pullup for the data-line, and is required to keep the data transfer stable. All sensors should share the same pins, and you only need one 4.7K resistor for all of them.
Diagram of connection of temperature sensor DS18B20.
Diagram of connection of temperature sensor DS18B20.
Diagram of connection of temperature sensor DS18B20.
Diagram of connection of temperature sensor DS18B20.
NOTE: In newer versions of the system, add the following entry to /boot/config.txt and restart the Raspberry PI.

   dtoverlay=w1-gpio,gpiopin=4
With this command we can check the attached devices for one wire.

   cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
To read the temperature from sensor, type the following command, replace device_id with your device identifier.

   cat /sys/bus/w1/devices/[device_id]/w1_slave
Step 4: Database creation

Now create a simple database containing only two tables.

Below the table in which we will store the connected devices.
Field   Description
name   Friendly name
dev_id   Device identifier

   CREATE TABLE w1_devices
   (
     w1_devices_id serial NOT NULL,
     name character varying(128) NOT NULL, -- Friendly name
     dev_id character varying(64) NOT NULL, -- Device identifier
     CONSTRAINT w1_devices_pkey PRIMARY KEY (w1_devices_id),
     CONSTRAINT w1_devices_dev_id_key UNIQUE (dev_id)
   )
Table containing temperature measurements.
Field   Description
date_insert   Measurement time
w1_devices_id   Row identifier from table "w1_devices"
temperature   The value of the measured temperature
date_check   Time of the last measurement.

   CREATE TABLE temperature
   (
     temperature_id serial NOT NULL,
     date_insert timestamp with time zone NOT NULL DEFAULT now(),
     w1_devices_id integer NOT NULL,
     temperature numeric(10,2),
     date_check timestamp with time zone,
     CONSTRAINT temperature_pkey PRIMARY KEY (temperature_id),
     CONSTRAINT temperature_w1_devices_id_fkey FOREIGN KEY (w1_devices_id)
         REFERENCES w1_devices (w1_devices_id) MATCH SIMPLE
         ON UPDATE NO ACTION ON DELETE NO ACTION
   )
Step 5: Script in PHP

Below is a script that will be executed every minute, via cron. This script measures the temperature of the sensors (DS18B20),
then compares the value of the measurement to the previous value. If the difference is greater than 0.1 degrees Celsius,
it inserts a new record into the table "temperature". If the difference is less than 0.1 degree celsius. This does the update of
the last measurement by changing the value of "date_check". I put this file in /var/www/html/

Before using these scripts, you need to configure your connection to the database server. I use an external
database on my server, but you can also use a local database on the Raspberry PI.

   $dbname='';
   $host='';
   $dbuser='';
   $dbpass='';
File temp.php
<?php
   error_reporting(E_ALL);
   ini_set('display_errors', 1);

   $dbname='';
   $host='';
   $dbuser='';
   $dbpass='';
   try {
      $db = new PDO("pgsql:dbname=$dbname;host=$host", $dbuser, $dbpass);
      $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   }catch(PDOException $e){
       echo "ERROR: " . $e->getMessage();
   }
   
   //----------------------------------
   $str = file_get_contents('/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves');
   $dev_ds18b20 = preg_split("/\\r\\n|\\r|\\n/", $str);
   
   
   foreach( $dev_ds18b20 as $val ){
      if( $val!='' ){
         //echo "DS18B20: $val
\r\n";
         $temp_path = "/sys/bus/w1/devices/$val/w1_slave";
         $str = file_get_contents($temp_path);
         if( preg_match('|t\=([0-9]+)|mi', $str, $m) ){
            $temp = $m[1] / 1000;
            //echo "temp=$temp
\r\n";
            SaveMeasurement( $db, $val, $temp);
         }
      }
   }
   //----------------------------------
   
   function SaveMeasurement($db, $dev_id, $temp){
      try {
         $sql = $db->query ("SELECT * FROM w1_devices WHERE dev_id='$dev_id'");
         $result = $sql->fetch( PDO::FETCH_ASSOC );
         if( $result===false ){
             die('You must first define the device: ');
          }else{
             $sql = $db->query ("SELECT * FROM temperature WHERE w1_devices_id='$result[w1_devices_id]' ORDER BY date_insert DESC LIMIT 1");
            $result = $sql->fetch( PDO::FETCH_ASSOC );
            $ins = true;
            if( $result!==false && abs($result['temperature'] - $temp) < 0.1 ){
               echo abs($result['temperature'] - $temp);
               $ins = false;
            }
            
            if( $ins ){
               $sql = "INSERT INTO temperature(w1_devices_id, temperature) VALUES(:w1_devices_id, :temperature)";
                $statement = $db->prepare($sql);
               $statement->bindValue(':w1_devices_id', $result['w1_devices_id']);
               $statement->bindValue(':temperature', $temp);
               $statement->execute();
               $statement->closeCursor();
            }else{
               $sql = "UPDATE temperature SET date_check=now() WHERE temperature_id=:temperature_id";
                $statement = $db->prepare($sql);
               $statement->bindValue(':temperature_id', $result['temperature_id']);
               $statement->execute();
               $statement->closeCursor();   
            }
             
          }
      }catch(PDOException $e){
          echo "ERROR: " . $e->getMessage();
      }
   }
?>
Now we will create a shell script.

   cd /var/www/html/
   nano cron_temp.sh
   chmod +x cron_temp.sh
File cron_temp.sh
php -f /var/www/html/temp.php
Then we add this file to corn.

   crontab -e
We add this line and save.

   * * * * * /var/www/html/cron_temp.sh
Saving the results of temperature measurement every minute should already work. Now display the results from the table "temperature".
For this purpose we write another two scripts.
File ds18b20.php
<?php
   error_reporting(E_ALL);
   ini_set('display_errors', 1);

   echo "time: " . time() . "\r\n
";

   $str = file_get_contents('/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves');
   $dev_ds18b20 = preg_split("/\\r\\n|\\r|\\n/", $str);
   
   
   foreach( $dev_ds18b20 as $val ){
      if( $val!='' ){
         echo "DS18B20: $val
\r\n";
         $temp_path = "/sys/bus/w1/devices/$val/w1_slave";
         $str = file_get_contents($temp_path);
         if( preg_match('|t\=([0-9]+)|mi', $str, $m) ){
            $temp = $m[1] / 1000;
            echo "temp=$temp
\r\n";
         }
      }
   }
   
   $dbname='';
   $host='';
   $dbuser='';
   $dbpass='';
   try {
      $db = new PDO("pgsql:dbname=$dbname;host=$host", $dbuser, $dbpass);
      $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   }catch(PDOException $e){
       echo "ERROR: " . $e->getMessage();
   }
   
   
   ?><div style="background-color: #a0a0a0; vertical-align: bottom;"><?php
   $sql = "
         SELECT * FROM (
            SELECT * FROM temperature ORDER BY date_insert DESC LIMIT 35
         ) AS T ORDER BY date_insert
         ";
    foreach ($db->query($sql) as $row) {
        ?><div style="display:inline-block; margin-right: 1px; background-color: #66b3ff; vertical-align: bottom; width: 50px; height: <?php echo 2 * $row['temperature']; ?>px;"><?php echo $row['temperature']; ?></div><?php

    }
   
?></div>
To automatically refresh the results every second, we use Jquery and AJAX.
File index.php
<?php
   error_reporting(E_ALL);
   ini_set('display_errors', 1);
   
   $dbname='';
   $host='';
   $dbuser='';
   $dbpass='';
   try {
      $db = new PDO("pgsql:dbname=$dbname;host=$host", $dbuser, $dbpass);
      $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   }catch(PDOException $e){
       echo "ERROR: " . $e->getMessage();
   }
   
?><html>
  <head>
    <title><?php echo exec('hostname'); ?></title>
   
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
   <script type="text/javascript">

      function check(){
         $.get( "ds18b20.php", function( data ) {
              $( "#result" ).html( data );
             
            });
      }
      
   </script>
   <script type="text/javascript">
   <!--
      setInterval( "check()" ,1000);
   //-->
   </script>
   
   
  </head>
  <body>

  <div id="result"></div>

  </body>
</html>
Download source code: all-files.zip
Step 6: The end

Below the table with temperature measurements. The sensor is mounted in my living room and the temperature update is one minute.
date_insert   temperature   date_check
2017-04-24 19:52:43   21.63 ℃   
2017-04-24 19:51:42   22.00 ℃   
2017-04-24 19:50:42   22.25 ℃   
2017-04-24 19:41:42   22.50 ℃   2017-04-24 19:49:42
2017-04-24 19:36:43   22.38 ℃   2017-04-24 19:40:43
2017-04-24 19:32:42   22.25 ℃   2017-04-24 19:35:42
2017-04-24 19:30:43   22.13 ℃   2017-04-24 19:31:42
2017-04-24 19:29:42   22.00 ℃   
2017-04-24 19:28:43   21.88 ℃   
2017-04-24 19:26:43   21.63 ℃   2017-04-24 19:27:43
2017-04-24 19:24:43   21.75 ℃   2017-04-24 19:25:43
2017-04-24 19:22:42   21.88 ℃   2017-04-24 19:23:42
2017-04-24 19:19:42   22.00 ℃   2017-04-24 19:21:43
2017-04-24 19:18:42   21.88 ℃   
2017-04-24 19:17:43   21.75 ℃   
2017-04-24 19:16:42   21.56 ℃   
2017-04-24 19:15:42   21.44 ℃   
2017-04-24 19:14:42   21.56 ℃   
2017-04-24 19:13:42   21.88 ℃   
2017-04-24 19:10:43   22.00 ℃   2017-04-24 19:12:42
2017-04-24 19:05:42   21.88 ℃   2017-04-24 19:09:43
2017-04-24 19:03:42   21.75 ℃   2017-04-24 19:04:42
2017-04-24 19:02:43   21.56 ℃   
2017-04-24 19:00:42   21.38 ℃   2017-04-24 19:01:42
2017-04-24 18:58:43   21.19 ℃   2017-04-24 18:59:43
2017-04-24 18:57:42   21.00 ℃   
2017-04-24 18:56:42   20.81 ℃   
2017-04-24 18:55:42   20.56 ℃   
2017-04-24 18:50:42   20.31 ℃   2017-04-24 18:54:42
2017-04-24 18:45:43   20.44 ℃   2017-04-24 18:49:42
2017-04-24 18:31:43   20.31 ℃   2017-04-24 18:44:43
2017-04-24 18:29:43   20.44 ℃   2017-04-24 18:30:43
2017-04-24 18:18:44   20.31 ℃   2017-04-24 18:28:43
2017-04-24 18:03:43   20.44 ℃   2017-04-24 18:17:42
2017-04-24 17:58:42   20.56 ℃   2017-04-24 18:02:43
2017-04-24 17:30:42   20.69 ℃   2017-04-24 17:57:42
2017-04-24 17:20:42   20.81 ℃   2017-04-24 17:29:42
2017-04-24 17:13:43   20.94 ℃   2017-04-24 17:19:43
2017-04-24 17:08:42   20.81 ℃   2017-04-24 17:12:43
2017-04-24 17:06:42   20.94 ℃   2017-04-24 17:07:42
2017-04-24 17:02:43   21.06 ℃   2017-04-24 17:05:42
2017-04-24 16:52:42   20.94 ℃   2017-04-24 17:01:43
2017-04-24 16:51:43   20.81 ℃   
2017-04-24 16:39:42   20.94 ℃   2017-04-24 16:50:43
2017-04-24 16:34:42   21.06 ℃   2017-04-24 16:38:43
2017-04-24 16:33:42   20.94 ℃   
2017-04-24 16:32:42   21.06 ℃   
2017-04-24 16:25:43   20.94 ℃   2017-04-24 16:31:42
2017-04-24 16:15:43   21.13 ℃   2017-04-24 16:24:43
2017-04-24 16:11:43   21.25 ℃   2017-04-24 16:14:43
2017-04-24 16:05:43   21.13 ℃   2017-04-24 16:10:42
2017-04-24 15:54:43   21.00 ℃   2017-04-24 16:04:43
2017-04-24 15:49:43   21.13 ℃   2017-04-24 15:53:42
2017-04-24 15:40:42   21.25 ℃   2017-04-24 15:48:42
2017-04-24 15:39:43   21.44 ℃   
2017-04-24 15:38:43   21.69 ℃   
2017-04-24 15:37:43   22.25 ℃   
2017-04-24 15:06:42   23.00 ℃   2017-04-24 15:36:43
2017-04-24 14:48:43   22.88 ℃   2017-04-24 15:05:42
2017-04-24 14:44:42   22.75 ℃   2017-04-24 14:47:42
2017-04-24 14:42:43   22.56 ℃   2017-04-24 14:43:43
2017-04-24 14:41:43   22.69 ℃   
2017-04-24 14:37:43   22.81 ℃   2017-04-24 14:40:43
2017-04-24 14:35:43   22.69 ℃   2017-04-24 14:36:42
2017-04-24 14:34:42   22.50 ℃   
2017-04-24 14:33:42   22.38 ℃   
2017-04-24 14:28:43   22.56 ℃   2017-04-24 14:32:43
2017-04-24 14:24:43   22.38 ℃   2017-04-24 14:27:43
2017-04-24 14:22:43   22.50 ℃   2017-04-24 14:23:43
2017-04-24 14:21:43   22.63 ℃   
2017-04-24 14:20:44   22.75 ℃   
2017-04-24 14:17:42   22.88 ℃   2017-04-24 14:19:43
2017-04-24 14:14:42   22.75 ℃   2017-04-24 14:16:42
2017-04-24 14:12:42   22.63 ℃   2017-04-24 14:13:42
2017-04-24 14:11:43   22.50 ℃   
2017-04-24 14:10:43   22.38 ℃   
2017-04-24 14:07:42   22.19 ℃   2017-04-24 14:09:43
2017-04-24 14:03:42   22.38 ℃   2017-04-24 14:06:43
2017-04-24 13:59:43   22.25 ℃   2017-04-24 14:02:43
2017-04-24 13:57:42   22.13 ℃   2017-04-24 13:58:43
2017-04-24 13:56:42   22.31 ℃   
2017-04-24 13:55:42   22.56 ℃   
2017-04-24 13:53:42   22.44 ℃   2017-04-24 13:54:42
2017-04-24 13:52:42   22.69 ℃   
2017-04-24 13:50:43   22.81 ℃   2017-04-24 13:51:43
2017-04-24 13:47:43   22.69 ℃   2017-04-24 13:49:43
2017-04-24 13:46:42   22.56 ℃   
2017-04-24 13:45:42   22.38 ℃   
2017-04-24 13:44:42   22.25 ℃   
2017-04-24 13:42:43   22.06 ℃   2017-04-24 13:43:42
2017-04-24 13:39:43   22.19 ℃   2017-04-24 13:41:43
2017-04-24 13:38:43   22.31 ℃   
2017-04-24 13:34:43   22.50 ℃   2017-04-24 13:37:43
2017-04-24 13:32:42   22.69 ℃   2017-04-24 13:33:42
2017-04-24 13:31:42   22.56 ℃   
2017-04-24 13:29:42   22.38 ℃   2017-04-24 13:30:43
2017-04-24 13:28:42   22.63 ℃   
2017-04-24 13:27:42   22.81 ℃   
2017-04-24 13:26:42   22.94 ℃   
2017-04-24 13:22:43   23.13 ℃   2017-04-24 13:25:42
#127
Raspberry Pi / Raspberry PI as Print server
April 24, 2017, 11:36:26 AM
From : http://www.techradar.com/how-to/computing/how-to-turn-the-raspberry-pi-into-a-wireless-printer-server-1312717


A printer isn't the most convenient of peripherals. They look out of place on most work desks and create quite a racket when spitting out pages.

You could throw a few hundred quid on a snazzy new network printer that sits in a corner somewhere and can receive print orders from any computer on the local network or you could just hook your regular USB printer to the Raspberry Pi and enjoy the same conveniences offered by top of the line network printers.

If you haven't already used your printer on Linux, before you get started with this project head to the Open Printing website to check whether your printer is compatible with the CUPS printing server software.

If your printer is listed, hook it up to the Raspberry Pi using one of the USB ports. For this project, we're using the Raspbian distro and the Raspberry Pi is connected to the local network via a compatible wireless adaptor.

However, you can also hook the Raspberry Pi up to your network via the wired Ethernet port.

You can follow the instructions in this tutorial by accessing the Raspberry Pi remotely from any other computer on the network. Just make sure that the SSH server inside Raspbian is enabled by using the raspi-config tool. It's also a good idea to assign a fixed IP address to the Raspberry Pi.

You can do this easily from within your router's admin page. For this tutorial we'll assume that the IP address of your Raspberry PI is 192.168.3.111.

You can now access the Pi from within Windows using the PuTTY client or from any Linux distro with the SSH CLI command with:

$ sudo ssh pi@192.168.3.111

Install CUPS

Once you're inside Raspbian, update the repositories (repos) with $ sudo apt-get update and then install any updates with $ sudo apt-get upgrade . Now pull in the CUPS print server with $ sudo apt-get install cups

When it's installed, add your user to the group created by CUPS called lpadmin that has access to the printer queue.

How to turn the Raspberry Pi into a wireless printer server

You can also browse through its extensive documentation from the CUPS browser-based control panel
Unless you have created a custom user, the default user on Raspbian is called pi. Use the following command to allow it to interact with the printer: $ sudo usermod -a -G lpadmin pi

Here we use the usermod tool to add ( -a ) the pi user to the lpadmin group ( -G ). By default, CUPS can only be configured from the local computer that it's installed on.

Because that doesn't work in our case, we need to edit its configuration file to allow us to make changes to the server from a remote computer. First of all, you need to create a backup of the original configuration file with:

$ sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.orig

Then open the file with the nano text editor: $ sudo nano /etc/cups/cupsd.conf . Inside the file, scroll down to the following section:

# Only listen for connections from the local machine
Listen localhost:631

Comment out that line (by adding the # to the beginning of the line) and add another to ask CUPS to accept connects from any computer on the network. Make sure the section looks like this:

# Only listen for connections from the local machine
# Listen localhost:631
Port 631

Then scroll further down in the configuration file until you reach the sections, and add a new line that reads Allow @local just before the close of the section. The section with the appended line should now read like this:


# Restrict access to the server
Order allow,deny
Allow @local

Now add the Allow @local line to the other two Location sections – and

Save the file and restart the CUPS server with: $ sudo /etc/init.d/cups restart

You should now be able to access the CUPS administration panel via any computer on your local network by pointing the web browser to your Pi. Then follow the walkthrough over the page to add your printer to CUPS.

Some Linux distros ship with a restrictive iptables firewall policy that doesn't allow connections via the CUPS ports.

Even if Raspbian doesn't, make sure it doesn't throw up any unexpected errors by punching holes in the firewall with:

$ sudo iptables -A INPUT -i wlan0 -p tcp -m tcp --dport 631 -j
ACCEPT
$ sudo iptables -A INPUT -i wlan0 -p udp -m udp --dport 631
-j ACCEPT

If you connect to the Raspberry Pi via Ethernet instead of a wireless adaptor, modify the command and replace wlan0 with eth0 . When you are through setting up your printer using the CUPS administration panel, it's time to make it accessible to other machines on your network.

While Linux distros will have no trouble detecting your new network printer, making them visible to Windows and Apple devices requires a couple of extra steps.

How to turn the Raspberry Pi into a wireless printer server

From the Printers tab, you can track the status of every job on every printer
Network-wide access

For Windows, install the Samba server on the Raspberry Pi with $ sudo apt-get install samba . Then open its configuration file (/etc/samba/smb.conf) in the nano text editor and hunt for the section labelled [printers] and make sure it contains the line:

guest ok = yes

Then scroll down to the [print$] section and change its path to the following:

path = /usr/share/cups/drivers

Then scroll up to the Global Settings section at the top of the configuration file. Modify the workgroup parameter within to point to the name of your workgroup, which by default is named WORKGROUP .

Also enable the wins support by adding the line wins support = yes

Now save the file and restart Samba with $ sudo /etc/init.d/samba restart .

Then head over to the Windows machine and launch the Add New Printer wizard and click on the option to install a network printer. Thanks to the modified Samba configuration, the wizard will detect and list any printers hooked up to the Raspberry Pi.

If you have Apple devices, you can enable support for Apple's AirPrint system, which allows you to print from the iPad and iPhone. For this, just install the Avahi daemon with sudo apt-get install avahi-daemon on the Raspberry Pi, which will then make the connected printer visible to AirPrint-compatible devices.

In addition to the ability to use our network printer from within graphical applications across all platforms, we can also use it to print from the command line interface. Furthermore, we can also interact with the printer using the Python programming language.
#128
Raspberry Pi / Raspberry PI Home Automation
April 24, 2017, 11:12:39 AM
https://diyhacking.com/raspberry-pi-home-automation/

1.Copy the files DIYhackingIoT.zip to a server.
2. Put Main.html , buttonStatus.txt , buttonStatus.php ,button.php in a directory that can be seen on the internet.   (/var/www/html/pibuttons)
3. Put rasbpi.py on the raspberry pi along with python and ssh into pi and run rasbpi.py
4. Goto webbrowser and put in ip or address of the Pi3 and turn on & off   
#131
General Discussion / Build LED Lights
April 11, 2017, 11:51:46 AM
 (Voltage of LEDs x How many LEDs = Voltage Drop) White LEDS  3.6x3=10.8 then (Power Supply Voltage - Voltage Drop =  additional Voltage drop) 12v-10.8=1.2
  (additional Voltage drop / milliamp = ohms)   1.2/.025ma =48 ohms

As an example, for a 12 volt light, you can run a maximum of 3 white LEDs in series at full power (3.6 x 3 = 10.8 volts drop).  Subtract this from your supply voltage of 12 volts to get the additional voltage that must be dropped (in this case, 12 - 10.8 = 1.2 volts of additional drop needed).  In this case, 1.2 volts of additional drop / .025 amps (25 ma) = 48 ohms.  Use the next highest value of resistor available, 50 ohms.  You must also be sure the resistor can handle enough current.  Volts x Amps = Watts; resistors are rated in watts.  So in this case, 1.2 volts x .025 amps = 0.03 watts.  A 1/4 watt resistor will work fine, but if you run a second string of 3 LEDs in parallel, each string would need its own 50 ohm resistor. It's important that each string has its own resistor....putting them in parallel with a single resistor is bad practice.

http://www.otherpower.com/otherpower_lighting_leds.html



#132
Arduino / Arduino MP3 Player with SD card
March 27, 2017, 03:36:27 PM
TO build Follow: https://www.instructables.com/id/Audio-Playback-From-SD-Card-With-Arduino/



Sketch


#include <SimpleSDAudio.h>
 
void setup()
{
 
SdPlay.setSDCSPin(4); // sd kart cs pini
 
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))
{
while(1);
}
 
if(!SdPlay.setFile("music.wav")) // müzik dosya adı
{
while(1); //dosya bulunamassa durdur
}
}
 
void loop(void) {
 
SdPlay.play(); // seçilen dosyayı çal
 
while(!SdPlay.isStopped()) { // müzik bittiğinde tekrar çal
;
}
}



// Sesli Renk Okuyan Robot Projesi
//Coder Sezgin Gül
// www.robimek.com
#include <SimpleSDAudio.h>
#include "Wire.h"
#include "Adafruit_TCS34725.h"
 
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X);
void setup() {
Serial.begin(9600);
 
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER)) {
while(1);
}
SdPlay.setSDCSPin(4);
if (tcs.begin()) {+-
Serial.println("Sensör bulundu");
} else {
Serial.println("TCS34725 Sensör bulunamadı !");
while (1); // Dur!
}
delay(1000);
 
}
void loop() {
 
uint16_t clearcol, red, green, blue;
float average, r, g, b;
tcs.getRawData(&red, &green, &blue, &clearcol);
 
average = (red+green+blue)/3;
r = red/average;
g = green/average;
b = blue/average;
Serial.print("\tTEMIZ:"); Serial.print(clearcol);
Serial.print("\tKIRMIZI:"); Serial.print(r);
Serial.print("\tYESIL:"); Serial.print(g);
Serial.print("\tMAVI:"); Serial.print(b);
 
if ((r > 1.4) && (g < 0.9) && (b < 0.9)) {
Serial.print("\tKIRMIZI");
SdPlay.setFile("krmz.wav");
SdPlay.play();
}
else if ((r < 0.95) && (g > 1.4) && (b < 0.9)) {
Serial.print("\tYESIL");
SdPlay.setFile("ysl.wav");
SdPlay.play();
}
else if ((r < 0.8) && (g < 1.2) && (b > 1.2)) {
Serial.print("\tMAVI");
SdPlay.setFile("mavi.wav");
SdPlay.play();
}
else if ((r > 1.15) && (g > 1.15) && (b < 0.7)) {
Serial.print("\tSARI");
SdPlay.setFile("sari.wav");
SdPlay.play();
}
else if ((r > 1.4) && (g < 1.0) && (b < 0.7)) {
Serial.print("\tTURUNCU");
SdPlay.setFile("trnc.wav");
SdPlay.play();
}
else {
Serial.print("\tRENK ALGILANMADI");
 
}
Serial.println("");
 
 
}
#133
How to wire a lithuim or 16850 battery pack.





3s1p   Fully charged 4.2V = 12.6v         3.7v= 11.1V

#134
Linux Fixes / Backup/Restoring Linux Mondo
February 28, 2017, 12:45:25 PM
http://www.mondorescue.org/docs/mondorescue-howto.html

TO start mondo from cmd line.
#  mondoarchive
#135

Convert VHDx to QCOW2
qemu-img convert -O qcow2 source.vhd destination.qcow2
qemu-img convert -O qcow2 rmcgmc01.vhdx rmcgmc01.qcow2
**qemu-img convert -f vpc -O qcow2 something.vhd something.qcow2**


Convert QCOW2  to VHD
qemu-img convert -f qcow2 -O vpc image.qcow2 image.vpc
or
qemu-img convert -f qcow2 -O vhd vmdisk.qcow2 vmdisk.vhd

#136
Linux Fixes / QEMU/KVM Image Location
February 15, 2017, 11:26:09 AM

The location of the image .qcow2

/var/lib/libvirt/images
#137
Linux Fixes / Create a ISO from CDROM
February 14, 2017, 12:21:31 PM

dd if=/dev/cdrom of=/path/to/image.iso


Create the mount point directory on Linux: sudo mkdir /mnt/iso
Mount the ISO file on Linux: sudo mount -o loop /path/to/my-iso-image.iso /mnt/iso
Verify it, run: mount OR df -H OR ls -l /mnt/iso/
Unmount the ISO file using: sudo umount /mnt/iso/
#138
Linux Fixes / Mount VHD or VHDx
February 13, 2017, 11:24:41 AM


1st. sudo apt-get install libguestfs-tools

2nd. guestmount -a anyvirtualdisk.vhdx -i --ro /mnt/anydirectory
#139
Linux Fixes / TO Get the Model Server
February 10, 2017, 03:03:41 PM
dmidecode |grep -i proliant
#140
Linux Fixes / SmartArray HP proliant raid drivers
February 10, 2017, 02:29:27 PM
http://cciss.sourceforge.net

to View info

smartctl -a -d cciss,0 /dev/cciss/c0d0    Shows drive 0
smartctl -a -d cciss,1 /dev/cciss/c0d0    Shows Drive 1

List all controllers:
hpacucli controller all show

List physical drives on controller in slot 0:
hpacucli ctrl slot=0 pd all show status

List physical drives Raid configuration
hpacucli ctrl slot=0 show config

hpacucli ctrl slot=0 ld all show detail