Sunday, January 16, 2022

How to reset your password in Raspberry PI when it you forget about the password?

Hardware
-Raspberry Pi 4 Model B

Problems
  • Working on Raspberry Pi recently on my robotics project, I altered /etc/rc.local to setup an auto job and this has caused my system unable to boot properly.
Solutions
  • Remove the SD Card from Raspberry Pi, mount it to your computer
  • Look for cmdline.txt, alter the file based on the value in bold
  • Original
console=tty1 root=PARTUUID=9f7945f8-02 rootfstype=ext4 elevator=deadline 
fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
  • Altered
console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline 
fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles 
init=/bin/sh
  • Insert the SD Card back to the Raspberry Pi board again, reboot the system.
  • Run command below to allowed the write access to the SD Card
mount -o remount, rw /
    • I reset my "pi" account password 
    sudo passwd pi
        • Remove the SD Card again from Raspberry Pi, mount it to computer.
        • Revert to the original command in cmdline.txt
        • Insert the SD Card back to the Raspberry Pi board again, reboot the system

        Wednesday, January 8, 2020

        How to enable remote connection in mongodb?

        Software Required
        -mongodb version 4.0.4
        -macOS Mojave

        Problems
        • Try to connect mongodb using the REMOTE_IP address on my mac machine, always encounter the error message as shown below. 
         
        server-0   | MongoError: failed to connect to server [REMOTE_IP:27017] 
        on first connect [MongoError: connect ECONNREFUSED REMOTE_IP:27017]
        
        
        • Use the telnet client to connect the mongodb
        telnet REMOTE_IP 27017
        
        
        • Error message as shown below is displayed
        Trying REMOTE_IP...
        telnet: connect to address REMOTE_IP: Connection refused
        telnet: Unable to connect to remote host
        
        

        Solutions
        • Open mongod.conf file that located at /usr/local/etc folder, add the REMOTE_IP into the file
        systemLog:
          destination: file
          path: /usr/local/var/log/mongodb/mongo.log
          logAppend: true
        storage:
          dbPath: /usr/local/var/mongodb
        net:
          bindIp: 127.0.0.1,REMOTE_IP
        
        
        • Restart mongodb using the command below, please include the path of mongod.conf in the command.
         # mongod --config /usr/local/etc/mongod.conf
        
        

        • Use the telnet client to connect the mongodb, it will work like a charm!
         telnet REMOTE_IP 27017
        
        
          Small quote: How people treat you is their karma, how you react is yours!

          Monday, January 6, 2020

          Error "Attempted to create a lock file on a read-only directory: /data/db, terminating" is displayed when start mongod

          Problems
          • Try to start mongodb on my machine using the command below
           mongod
          • Error as shown below is displayed
          ...
          2020-01-06T23:33:40.434-0600 I STORAGE  [initandlisten] exception in initAndListen: 
          IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, 
          terminating
          ...

          Solutions

          • Run the command below to grant the current user to have the write access to /data/db directory, it will work like a charm when you restart the mongodb again.
           sudo chown -R $USER /data/db

          Wednesday, March 6, 2019

          How to hide warning message in React Native app?

          Software Required
          -NPM version 6.4.1
          -expo version 2.6.14
          -Atom 1.34.0

          Problems
          • During my development, encounter error as shown below when try to test it on Expo client.
          Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.



          Steps
        • Add the line as shown below into your App.js
        •  console.disableYellowBox = true;  
          
        • It may not solve the root cause of the problem, it may temporary hide the uncomfortable warning message on your App. Meanwhile, it buy you time to look for solution if you need a quick release.
        •  
          ...
          render() {
              console.disableYellowBox = true;
              ...  
          

          Wednesday, February 13, 2019

          How to resolve "requireNativeComponent: "BVLinearGradient" was not found in the UIManager" error message in React Native project?

          Software Required
          -NPM version 6.4.1
          -expo version 2.6.14
          -Atom 1.34.0

          Problems
          • During my development, encounter error as shown below when try to test it on Expo client.
          Invariant Violation: requireNativeComponent: "BVLinearGradient" was not found in the UIManager.

          Steps
        • Import "LinearGradient" class from expo. It will work like a charm.
        •  import { LinearGradient } from 'expo';

          Monday, February 11, 2019

          How to resolve Expo client hanging issue when follow the NativeBase ReactNavigation tutorial?

          Software Required
          NPM version 6.4.1
          expo version 2.6.14
          Atom 1.34.0
          NativeBase 2.10.0. Please refer to link

          Problems

          • Follow the sample tutorial provided by NativeBase and it hang my Expo client.
          • Below are the sample code that I used from NativeBased tutorial.
          import React, { Component } from "react";
          import Expo from "expo";
          import HomeScreen from "./src/HomeScreen/index.js";
          export default class AwesomeApp extends Component {
            constructor() {
              super();
              this.state = {
                isReady: false
              };
            }
            async componentWillMount() {
              await Expo.Font.loadAsync({
                Roboto: require("native-base/Fonts/Roboto.ttf"),
                Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf"),
                Ionicons: require("native-base/Fonts/Ionicons.ttf")
              });
              this.setState({ isReady: true });
            }
            render() {
              if (!this.state.isReady) {
                return <Expo.AppLoading />;
              }
              return <HomeScreen />;
            }
          }
          
          
          Steps
          • After a long troubleshooting, I manage to identify the line as shown below that caused the hang.
          ...
              await Expo.Font.loadAsync({
          ...
          
          • Replace App.js with the sample source as shown, remove "Expo." before the Font.loadAsync, it just working great. No more hanging in my Expo client.
          import React, { Component } from "react";
          import HomeScreen from "./src/HomeScreen/index.js";
          import {Font, Expo, AppLoading} from 'expo';
          export default class AwesomeApp extends Component {
            state={
              isReady: false
            }
          
            constructor() {
              super();
            }
          
            async componentWillMount() {
              await Font.loadAsync({
                Roboto: require("native-base/Fonts/Roboto.ttf"),
                Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf"),
                Ionicons: require("native-base/Fonts/Ionicons.ttf")
              });
              this.setState({ isReady: true });
            }
          
            render() {
              if (!this.state.isReady) {
                    return <AppLoading />;
              }
          
              return <HomeScreen />;
            }
          }
          
          

          How to resolve "The Image component cannot contain children." error message when follow the NativeBase ReactNavigation tutorial?

          Software Required
          NPM version 6.4.1
          expo version 2.6.14
          Atom 1.34.0
          NativeBase 2.10.0. Please refer to link

          Problems

          • Follow the sample tutorial provided by NativeBase and encounter error message as shown below.
          Error: Error: The <image> component cannot contain children. If you want to render content on top of image, consider using the <ImageBackground> component or absolute positioning.
          • Troubleshoot the source code and discovered that the Image component in SideBar.js that caused the error message
          import React from "react";
          import { AppRegistry, Image, StatusBar } from "react-native";
          import { Container, Content, Text, List, ListItem } from "native-base";
          const routes = ["Home", "Chat", "Profile"];
          export default class SideBar extends React.Component {
            render() {
              return (
                <Container>
                  <Content>
                    <Image
                      source={{
                        uri: "https://github.com/GeekyAnts/NativeBase-KitchenSink/raw/react-navigation/img/drawer-cover.png"
                      }}
                      style={{
                        height: 120,
                        alignSelf: "stretch",
                        justifyContent: "center",
                        alignItems: "center"
                      }}>
                      <Image
                        square
                        style={{ height: 80, width: 70 }}
                        source={{
                          uri: "https://github.com/GeekyAnts/NativeBase-KitchenSink/raw/react-navigation/img/logo.png"
                        }}
                      />
                    </Image>
                    <List
                      dataArray={routes}
                      renderRow={data => {
                        return (
                          <ListItem
                            button
                            onPress={() => this.props.navigation.navigate(data)}>
                            <Text>{data}</Text>
                          </ListItem>
                        );
                      }}
                    />
                  </Content>
                </Container>
              );
            }
          }
          
          
          Steps
          • Obviously, Image component as shown in the section below that caused the problem.
          
            render() {
          ...
                    <Image
                      source={{
                        uri: "https://github.com/GeekyAnts/NativeBase-KitchenSink/raw/react-navigation/img/drawer-cover.png"
                      }}
                      style={{
                        height: 120,
                        alignSelf: "stretch",
                        justifyContent: "center",
                        alignItems: "center"
                      }}>
          ...
              );
            }
          }
          
          
          • I fixed the issue with ImageBackground as shown in the section below, it works like a charm
          import React from "react";
          import { AppRegistry, Image, StatusBar, ImageBackground } from "react-native";
          import { Container, Content, Text, List, ListItem } from "native-base";
          const routes = ["Home", "Chat", "Profile"];
          
          export default class SideBar extends React.Component {
            render() {
              return (
                <Container>
                  <Content>
                    <ImageBackground
                      source={require("../../images/drawer-cover.png")}
                      style={{
                        height: 120,
                        alignSelf: "stretch",
                        justifyContent: "center",
                        alignItems: "center"
                      }}>
                      <Image
                        square
                        style={{ height: 80, width: 70 }}
                        source={require("../../images/logo.png")}
                      />
                    </ImageBackground>
                    <List
                      dataArray={routes}
                      renderRow={data => {
                        return (
                          <ListItem
                            button
                            onPress={() => this.props.navigation.navigate(data)}>
                            <Text>{data}</Text>
                          </ListItem>
                        );
                      }}
                    />
                  </Content>
                </Container>
              );
            }
          }